From 03ab50821418fac99578fd762ba1ef135671b545 Mon Sep 17 00:00:00 2001 From: Daniel Kareh Date: Tue, 4 Aug 2026 17:43:34 -0400 Subject: [PATCH] std.Io.Dir.path: make the behavior of `stem` match its documentation --- lib/std/fs/path.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig index ffba84b9e3f80c70fa9de109525bf8a3f3262ed2..d5b7f751acf77f6a4b98951f8039bbbf4c20b752 100644 --- a/lib/std/fs/path.zig +++ b/lib/std/fs/path.zig @@ -1887,8 +1887,8 @@ test extension { /// - "hello/world/lib" ⇒ "lib" pub fn stem(path: []const u8) []const u8 { const filename = basename(path); - const index = mem.findScalarLast(u8, filename, '.') orelse return filename[0..]; - if (index == 0) return path; + const index = mem.findScalarLast(u8, filename, '.') orelse return filename; + if (index == 0) return filename; return filename[0..index]; } @@ -1904,8 +1904,14 @@ test stem { try testStem("hello...", "hello.."); try testStem("hello.", "hello"); try testStem("/hello.", "hello"); + try testStem("hello/world/.gitignore", ".gitignore"); + try testStem("/.gitignore", ".gitignore"); try testStem(".gitignore", ".gitignore"); + try testStem(".gitignore/", ".gitignore"); + try testStem("hello/world/.image.png", ".image"); + try testStem("/.image.png", ".image"); try testStem(".image.png", ".image"); + try testStem(".image.png/", ".image"); try testStem("file.ext", "file"); try testStem("file.ext.", "file.ext"); try testStem("a.b.c", "a.b"); -- 2.54.0