From eccc6700dcf91db0b7e54c3ea7795c5d1ddd4bc9 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 9 Nov 2025 21:45:19 +0100 Subject: [PATCH] - Fix appending to `c:\` or `\` #2569. --- lib/std/io/path.c3 | 4 +--- releasenotes.md | 1 + test/unit/stdlib/io/path.c3 | 13 +++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index d98251018..858dbda0e 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -186,13 +186,11 @@ fn bool Path.equals(self, Path p2) @operator(==) fn Path? Path.append(self, Allocator allocator, String filename) { if (!self.path_string.len) return new(allocator, filename, self.env)!; - assert(!is_separator(self.path_string[^1], self.env)); - @pool() { DString dstr = dstring::temp_with_capacity(self.path_string.len + 1 + filename.len); dstr.append(self.path_string); - dstr.append(PREFERRED_SEPARATOR); + if (!is_separator(self.path_string[^1], self.env)) dstr.append(PREFERRED_SEPARATOR); dstr.append(filename); return new(allocator, dstr.str_view(), self.env); }; diff --git a/releasenotes.md b/releasenotes.md index 48d25ab1a..677634f3d 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -19,6 +19,7 @@ - Passing a compile time type implicitly converted to a typeid would crash instead of producing an error. #2568 - Compiler assert with const enum based on vector #2566 - Fix to `Path` handling `c:\foo` and `\home` parent. #2569 +- Fix appending to `c:\` or `\` #2569. ### Stdlib changes diff --git a/test/unit/stdlib/io/path.c3 b/test/unit/stdlib/io/path.c3 index e77d2b5ec..fdc86b2d6 100644 --- a/test/unit/stdlib/io/path.c3 +++ b/test/unit/stdlib/io/path.c3 @@ -1,5 +1,18 @@ module std::io::path @test; +fn void test_append() +{ + Path p = path::new(mem, "/", POSIX)!!; + Path p2 = p.append(mem, "hello")!!; + test::eq(p2.str_view(), "/hello"); + p.free(); + p2.free(); + p = path::new(mem, "c:\\", WIN32)!!; + p2 = p.append(mem, "hello")!!; + assert(p2.str_view() == "c:\\hello"); + p.free(); + p2.free(); +} fn void test_dot() { Path p = path::new(mem, ".")!!;