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 {...@@ -1887,8 +1887,8 @@ test extension {
1887/// - "hello/world/lib" ⇒ "lib"1887/// - "hello/world/lib" ⇒ "lib"
1888pub fn stem(path: []const u8) []const u8 {1888pub fn stem(path: []const u8) []const u8 {
1889 const filename = basename(path);1889 const filename = basename(path);
1890 const index = mem.findScalarLast(u8, filename, '.') orelse return filename[0..];1890 const index = mem.findScalarLast(u8, filename, '.') orelse return filename;
1891 if (index == 0) return path;1891 if (index == 0) return filename;
1892 return filename[0..index];1892 return filename[0..index];
1893}1893}
18941894
...@@ -1904,8 +1904,14 @@ test stem {...@@ -1904,8 +1904,14 @@ test stem {
1904 try testStem("hello...", "hello..");1904 try testStem("hello...", "hello..");
1905 try testStem("hello.", "hello");1905 try testStem("hello.", "hello");
1906 try testStem("/hello.", "hello");1906 try testStem("/hello.", "hello");
1907 try testStem("hello/world/.gitignore", ".gitignore");
1908 try testStem("/.gitignore", ".gitignore");
1907 try testStem(".gitignore", ".gitignore");1909 try testStem(".gitignore", ".gitignore");
1910 try testStem(".gitignore/", ".gitignore");
1911 try testStem("hello/world/.image.png", ".image");
1912 try testStem("/.image.png", ".image");
1908 try testStem(".image.png", ".image");1913 try testStem(".image.png", ".image");
1914 try testStem(".image.png/", ".image");
1909 try testStem("file.ext", "file");1915 try testStem("file.ext", "file");
1910 try testStem("file.ext.", "file.ext");1916 try testStem("file.ext.", "file.ext");
1911 try testStem("a.b.c", "a.b");1917 try testStem("a.b.c", "a.b");