diff options
| author | root <fancl20@gmail.com> | 2021-03-18 09:33:08 +1100 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2021-03-18 14:33:38 +0200 |
| commit | 75a7abb0c47d9f5e99b1f69250776528fa60f569 (patch) | |
| tree | 8696e9890cc406d69b70fd53583e108c7aeb0d36 /lib/std | |
| parent | bcc97bc1ed781c261ece5ff9a33ee9c1e621b62a (diff) | |
| download | zig-75a7abb0c47d9f5e99b1f69250776528fa60f569.tar.gz zig-75a7abb0c47d9f5e99b1f69250776528fa60f569.zip | |
std: Fix std.fs.path.joinZ
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fs/path.zig | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig index 776cb4040c..0bba522fb6 100644 --- a/lib/std/fs/path.zig +++ b/lib/std/fs/path.zig @@ -92,7 +92,7 @@ pub fn join(allocator: *Allocator, paths: []const []const u8) ![]u8 { /// Naively combines a series of paths with the native path seperator and null terminator. /// Allocates memory for the result, which must be freed by the caller. pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 { - const out = joinSepMaybeZ(allocator, sep, isSep, paths, true); + const out = try joinSepMaybeZ(allocator, sep, isSep, paths, true); return out[0 .. out.len - 1 :0]; } @@ -119,6 +119,16 @@ fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bo } test "join" { + { + const actual: []u8 = try join(testing.allocator, &[_][]const u8{}); + defer testing.allocator.free(actual); + testing.expectEqualSlices(u8, "", actual); + } + { + const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{}); + defer testing.allocator.free(actual); + testing.expectEqualSlices(u8, "", actual); + } for (&[_]bool{ false, true }) |zero| { testJoinMaybeZWindows(&[_][]const u8{}, "", zero); testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); |
