Skip to content

Commit

Permalink
Merge pull request #26 from CloudCannon/fix/strip-top-path
Browse files Browse the repository at this point in the history
Strip top path should handle leading/trailing slashes
  • Loading branch information
rphillips-cc authored Oct 2, 2024
2 parents d130e15 + 7b99530 commit 1cbdf26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function joinPaths(paths) {
* @returns {string}
*/
export function stripTopPath(path, stripPath) {
stripPath = normalisePath(stripPath || '');
if (path === stripPath) {
return '';
}
Expand Down
5 changes: 5 additions & 0 deletions test/utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 1cbdf26

Please sign in to comment.