From 7b995307226e31532dc93901e297d301ccfae402 Mon Sep 17 00:00:00 2001 From: Ryan Collins Date: Wed, 2 Oct 2024 13:13:19 +1300 Subject: [PATCH] Strip top path should handle leading/trailing slashes --- src/utility.js | 1 + test/utility.test.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/utility.js b/src/utility.js index 8b750bd..72d9619 100644 --- a/src/utility.js +++ b/src/utility.js @@ -30,6 +30,7 @@ export function joinPaths(paths) { * @returns {string} */ export function stripTopPath(path, stripPath) { + stripPath = normalisePath(stripPath || ''); if (path === stripPath) { return ''; } diff --git a/test/utility.test.js b/test/utility.test.js index aad68f9..b8eb554 100644 --- a/test/utility.test.js +++ b/test/utility.test.js @@ -16,9 +16,14 @@ test('joins paths', (t) => { test('strips top path', (t) => { t.is(stripTopPath('src/content/index.html', 'src'), 'content/index.html'); + t.is(stripTopPath('src/content/index.html', 'src/'), 'content/index.html'); + t.is(stripTopPath('src/content/index.html', '/src'), 'content/index.html'); + t.is(stripTopPath('src/content/index.html', '/src/'), 'content/index.html'); + t.is(stripTopPath('src/content/index.html', '/src/'), 'content/index.html'); t.is(stripTopPath('src/index.html', 'src'), 'index.html'); t.is(stripTopPath('src/index.html', ''), 'src/index.html'); t.is(stripTopPath('src', 'src'), ''); + t.is(stripTopPath('src', '/src/'), ''); t.is(stripTopPath('src', ''), 'src'); t.is(stripTopPath('sauce/content', 'sauce'), 'content');