- Fix appending to c:\ or \ #2569.

This commit is contained in:
Christoffer Lerno
2025-11-09 21:45:19 +01:00
parent 52ececba37
commit eccc6700dc
3 changed files with 15 additions and 3 deletions

View File

@@ -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);
};

View File

@@ -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

View File

@@ -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, ".")!!;