From 1110eafe9bd19ff69e9a7e488a7e9613fa909aeb Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Fri, 1 Jul 2022 12:21:06 +0200 Subject: [PATCH] Module: fix error message importing file starting with root path --- src/Module.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Module.zig b/src/Module.zig index 8bb5a94c1..85cc0f14b 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4694,7 +4694,11 @@ pub fn importFile( const resolved_root_path = try std.fs.path.resolve(gpa, &[_][]const u8{cur_pkg_dir_path}); defer gpa.free(resolved_root_path); - if (!mem.startsWith(u8, resolved_path, resolved_root_path)) { + if (!mem.startsWith(u8, resolved_path, resolved_root_path) or + // This prevents this check from triggering when the name of the + // imported file starts with the root path's directory name. + mem.indexOfAny(u8, &.{resolved_path[resolved_root_path.len]}, "/\\") == null) + { return error.ImportOutsidePkgPath; } // +1 for the directory separator here.