From f267c1d097923a2d2992f9f60a6dd365fe706512 Mon Sep 17 00:00:00 2001 From: Ai Hoshino Date: Tue, 12 Sep 2023 08:53:43 +0800 Subject: fix(path): Fix edge case in `path.relative` (#4811) Close: #4789 --- test/js/node/path/path.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/js/node/path/path.test.js') diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js index 3c8a04d72..5865d6182 100644 --- a/test/js/node/path/path.test.js +++ b/test/js/node/path/path.test.js @@ -415,6 +415,9 @@ it("path.join", () => { it("path.relative", () => { const failures = []; + const cwd = process.cwd(); + const cwdParent = path.dirname(cwd); + const parentIsRoot = cwdParent == "/"; const relativeTests = [ // [ @@ -477,6 +480,16 @@ it("path.relative", () => { ["/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"], + ["/app/node_modules/pkg", "../static", `../../..${parentIsRoot ? "" : cwdParent}/static`], + ["/app/node_modules/pkg", "../../static", `../../..${parentIsRoot ? "" : path.dirname(cwdParent)}/static`], + ["/app", "../static", `..${parentIsRoot ? "" : cwdParent}/static`], + ["/app", "../".repeat(64) + "static", "../static"], + [".", "../static", cwd == "/" ? "static" : "../static"], + ["/", "../static", parentIsRoot ? "static" : `${cwdParent}/static`.slice(1)], + ["../", "../", ""], + ["../", "../../", parentIsRoot ? "" : ".."], + ["../../", "../", parentIsRoot ? "" : path.basename(cwdParent)], + ["../../", "../../", ""], ], ], ]; -- cgit v1.2.3