authorgravatar for dkareh@noreply.codeberg.orgDaniel Kareh <dkareh@noreply.codeberg.org> 2026-08-04 17:43:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-04 19:12:22-07:00
log03ab50821418fac99578fd762ba1ef135671b545
tree7917ccf48bb14c16d2a687de05fd3f6117db311a
parentab4028d5796c68ca3aeb649e475bceff394942fc

std.Io.Dir.path: make the behavior of `stem` match its documentation


1 files changed, 8 insertions(+), 2 deletions(-)

lib/std/fs/path.zig+8-2
......@@ -1887,8 +1887,8 @@ test extension {
18871887/// - "hello/world/lib" ⇒ "lib"
18881888pub fn stem(path: []const u8) []const u8 {
18891889 const filename = basename(path);
1890 const index = mem.findScalarLast(u8, filename, '.') orelse return filename[0..];
1891 if (index == 0) return path;
1890 const index = mem.findScalarLast(u8, filename, '.') orelse return filename;
1891 if (index == 0) return filename;
18921892 return filename[0..index];
18931893}
18941894
......@@ -1904,8 +1904,14 @@ test stem {
19041904 try testStem("hello...", "hello..");
19051905 try testStem("hello.", "hello");
19061906 try testStem("/hello.", "hello");
1907 try testStem("hello/world/.gitignore", ".gitignore");
1908 try testStem("/.gitignore", ".gitignore");
19071909 try testStem(".gitignore", ".gitignore");
1910 try testStem(".gitignore/", ".gitignore");
1911 try testStem("hello/world/.image.png", ".image");
1912 try testStem("/.image.png", ".image");
19081913 try testStem(".image.png", ".image");
1914 try testStem(".image.png/", ".image");
19091915 try testStem("file.ext", "file");
19101916 try testStem("file.ext.", "file.ext");
19111917 try testStem("a.b.c", "a.b");