From e40a55c7f0554dd7db6b17d2d4b19f3d84744371 Mon Sep 17 00:00:00 2001 From: April Arcus Date: Wed, 15 Feb 2023 21:35:55 +0000 Subject: [PATCH] fix parent path traversal Previously, parentDir behaved as an identity function when its input ended with a trailing '/', making it impossible to build projects with imports from parent directories. --- es6.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/es6.js b/es6.js index 71e3647..825fe88 100644 --- a/es6.js +++ b/es6.js @@ -47,6 +47,9 @@ define([ // leaving the slash in the result. If there is no slash in the path - the path // is just a file name, it will return `undefined`. function parentDir (path) { + if (path[path.length - 1] === '/') { + path = path.substring(0, path.length - 1) + } var lastSlash = path.lastIndexOf('/'); return lastSlash > 0 ? path.substring(0, lastSlash + 1) : undefined; }