authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-12-18 23:55:13-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:10-08:00
log8767a9a6d1f6d92a1e9a98a31cb6dc98eb2c59f3
treedd4e4ab4e9ec15f8bf6680f6c73291ecde2d89a9
parentc1b9c46319ff6c76484121c177086b1fbe70d50c

testFilenameLimits: Fix collision with dir and filename


1 files changed, 14 insertions(+), 9 deletions(-)

lib/std/fs/test.zig+14-9
......@@ -1380,12 +1380,12 @@ test "makepath ignores '.'" {
13801380 try expectDir(io, tmp.dir, expectedPath);
13811381}
13821382
1383fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void {
1383fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8, maxed_dirname: []const u8) !void {
13841384 // create a file, a dir, and a nested file all with maxed filenames
13851385 {
13861386 try iterable_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
13871387
1388 var maxed_dir = try iterable_dir.makeOpenPath(io, maxed_filename, .{});
1388 var maxed_dir = try iterable_dir.makeOpenPath(io, maxed_dirname, .{});
13891389 defer maxed_dir.close(io);
13901390
13911391 try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
......@@ -1427,18 +1427,23 @@ test "max file name component lengths" {
14271427
14281428 if (native_os == .windows) {
14291429 // U+FFFF is the character with the largest code point that is encoded as a single
1430 // UTF-16 code unit, so Windows allows for NAME_MAX of them.
1431 const maxed_windows_filename = ("\u{FFFF}".*) ** windows.NAME_MAX;
1432 try testFilenameLimits(io, tmp.dir, &maxed_windows_filename);
1430 // WTF-16 code unit, so Windows allows for NAME_MAX of them.
1431 const maxed_windows_filename1 = ("\u{FFFF}".*) ** windows.NAME_MAX;
1432 // This is also a code point that is encoded as one WTF-16 code unit, but
1433 // three WTF-8 bytes, so it exercises the limits of both WTF-16 and WTF-8 encodings.
1434 const maxed_windows_filename2 = ("€".*) ** windows.NAME_MAX;
1435 try testFilenameLimits(io, tmp.dir, &maxed_windows_filename1, &maxed_windows_filename2);
14331436 } else if (native_os == .wasi) {
14341437 // On WASI, the maxed filename depends on the host OS, so in order for this test to
14351438 // work on any host, we need to use a length that will work for all platforms
14361439 // (i.e. the minimum max_name_bytes of all supported platforms).
1437 const maxed_wasi_filename = [_]u8{'1'} ** 255;
1438 try testFilenameLimits(io, tmp.dir, &maxed_wasi_filename);
1440 const maxed_wasi_filename1 = [_]u8{'1'} ** 255;
1441 const maxed_wasi_filename2 = [_]u8{'2'} ** 255;
1442 try testFilenameLimits(io, tmp.dir, &maxed_wasi_filename1, &maxed_wasi_filename2);
14391443 } else {
1440 const maxed_ascii_filename = [_]u8{'1'} ** std.fs.max_name_bytes;
1441 try testFilenameLimits(io, tmp.dir, &maxed_ascii_filename);
1444 const maxed_ascii_filename1 = [_]u8{'1'} ** std.fs.max_name_bytes;
1445 const maxed_ascii_filename2 = [_]u8{'2'} ** std.fs.max_name_bytes;
1446 try testFilenameLimits(io, tmp.dir, &maxed_ascii_filename1, &maxed_ascii_filename2);
14421447 }
14431448}
14441449