diff options
-rw-r--r-- | src/resolver/resolve_path.zig | 13 | ||||
-rw-r--r-- | test/js/node/path/path.test.js | 8 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index 877f32ded..4800d7d90 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -294,13 +294,20 @@ pub fn longestCommonPathGeneric(input: []const []const u8, comptime separator: u // /app/public/ // To detect /app/public is actually a folder, we do one more loop through the strings // and say, "do one of you have a path separator after what we thought was the end?" - for (input) |str| { + var idx = input.len; // Use this value as an invalid value. + for (input, 0..) |str, i| { if (str.len > index) { if (@call(.always_inline, isPathSeparator, .{str[index]})) { - return str[0 .. index + 1]; + idx = i; + } else { + idx = input.len; + break; } } } + if (idx != input.len) { + return input[idx][0 .. index + 1]; + } return input[0][0 .. last_common_separator + 1]; } @@ -340,7 +347,7 @@ pub fn relativeToCommonPath( const shortest = @min(normalized_from.len, normalized_to.len); - var last_common_separator = strings.lastIndexOfChar(_common_path, separator) orelse 0; + const last_common_separator = strings.lastIndexOfChar(_common_path, separator) orelse 0; if (shortest == common_path.len) { if (normalized_to.len > normalized_from.len) { diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js index 030a7443a..103809d2e 100644 --- a/test/js/node/path/path.test.js +++ b/test/js/node/path/path.test.js @@ -469,6 +469,14 @@ it("path.relative", () => { ["/baz", "/baz-quux", "../baz-quux"], ["/page1/page2/foo", "/", "../../.."], [process.cwd(), "foo", "foo"], + ["/webpack", "/webpack", ""], + ["/webpack/", "/webpack", ""], + ["/webpack", "/webpack/", ""], + ["/webpack/", "/webpack/", ""], + ["/webpack-hot-middleware", "/webpack/buildin/module.js", "../webpack/buildin/module.js"], + ["/webp4ck-hot-middleware", "/webpack/buildin/module.js", "../webpack/buildin/module.js"], + ["/webpack-hot-middleware", "/webp4ck/buildin/module.js", "../webp4ck/buildin/module.js"], + ["/var/webpack-hot-middleware", "/var/webpack/buildin/module.js", "../webpack/buildin/module.js"], ], ], ]; |