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 '.'" {...@@ -1380,12 +1380,12 @@ test "makepath ignores '.'" {
1380 try expectDir(io, tmp.dir, expectedPath);1380 try expectDir(io, tmp.dir, expectedPath);
1381}1381}
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 {
1384 // create a file, a dir, and a nested file all with maxed filenames1384 // create a file, a dir, and a nested file all with maxed filenames
1385 {1385 {
1386 try iterable_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });1386 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, .{});
1389 defer maxed_dir.close(io);1389 defer maxed_dir.close(io);
13901390
1391 try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });1391 try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
...@@ -1427,18 +1427,23 @@ test "max file name component lengths" {...@@ -1427,18 +1427,23 @@ test "max file name component lengths" {
14271427
1428 if (native_os == .windows) {1428 if (native_os == .windows) {
1429 // U+FFFF is the character with the largest code point that is encoded as a single1429 // 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.1430 // WTF-16 code unit, so Windows allows for NAME_MAX of them.
1431 const maxed_windows_filename = ("\u{FFFF}".*) ** windows.NAME_MAX;1431 const maxed_windows_filename1 = ("\u{FFFF}".*) ** windows.NAME_MAX;
1432 try testFilenameLimits(io, tmp.dir, &maxed_windows_filename);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);
1433 } else if (native_os == .wasi) {1436 } else if (native_os == .wasi) {
1434 // On WASI, the maxed filename depends on the host OS, so in order for this test to1437 // On WASI, the maxed filename depends on the host OS, so in order for this test to
1435 // work on any host, we need to use a length that will work for all platforms1438 // work on any host, we need to use a length that will work for all platforms
1436 // (i.e. the minimum max_name_bytes of all supported platforms).1439 // (i.e. the minimum max_name_bytes of all supported platforms).
1437 const maxed_wasi_filename = [_]u8{'1'} ** 255;1440 const maxed_wasi_filename1 = [_]u8{'1'} ** 255;
1438 try testFilenameLimits(io, tmp.dir, &maxed_wasi_filename);1441 const maxed_wasi_filename2 = [_]u8{'2'} ** 255;
1442 try testFilenameLimits(io, tmp.dir, &maxed_wasi_filename1, &maxed_wasi_filename2);
1439 } else {1443 } else {
1440 const maxed_ascii_filename = [_]u8{'1'} ** std.fs.max_name_bytes;1444 const maxed_ascii_filename1 = [_]u8{'1'} ** std.fs.max_name_bytes;
1441 try testFilenameLimits(io, tmp.dir, &maxed_ascii_filename);1445 const maxed_ascii_filename2 = [_]u8{'2'} ** std.fs.max_name_bytes;
1446 try testFilenameLimits(io, tmp.dir, &maxed_ascii_filename1, &maxed_ascii_filename2);
1442 }1447 }
1443}1448}
14441449