-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure that trailingSlashes don't break path matching (#1711)
* fix: ensure that trailingSlashes don't break path matching * chore: this wasn't on purpose * fix: make `removeTrailingSlash` account for basepath * test: tests for basepath * refactor: consolidate how we handle basepath replacing * test: matrix tests with different basepaths for utils * refactor: revert basereplace
- Loading branch information
Showing
6 changed files
with
252 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { exactPathTest, removeTrailingSlash } from '../src/path' | ||
|
||
describe.each([{ basepath: '/' }, { basepath: '/app' }, { basepath: '/app/' }])( | ||
'removeTrailingSlash with basepath $basepath', | ||
({ basepath }) => { | ||
it('should remove trailing slash if present', () => { | ||
const input = 'https://example.com/' | ||
const expectedOutput = 'https://example.com' | ||
const result = removeTrailingSlash(input, basepath) | ||
expect(result).toBe(expectedOutput) | ||
}) | ||
it('should not modify the string if no trailing slash present', () => { | ||
const input = 'https://example.com' | ||
const result = removeTrailingSlash(input, basepath) | ||
expect(result).toBe(input) | ||
}) | ||
it('should handle empty string', () => { | ||
const input = '' | ||
const result = removeTrailingSlash(input, basepath) | ||
expect(result).toBe(input) | ||
}) | ||
it('should handle strings with only a slash', () => { | ||
const input = '/' | ||
const result = removeTrailingSlash(input, basepath) | ||
expect(result).toBe(input) | ||
}) | ||
it('should handle strings with multiple slashes', () => { | ||
const input = 'https://example.com/path/to/resource/' | ||
const expectedOutput = 'https://example.com/path/to/resource' | ||
const result = removeTrailingSlash(input, basepath) | ||
expect(result).toBe(expectedOutput) | ||
}) | ||
}, | ||
) | ||
|
||
describe.each([{ basepath: '/' }, { basepath: '/app' }, { basepath: '/app/' }])( | ||
'exactPathTest with basepath $basepath', | ||
({ basepath }) => { | ||
it('should return true when two paths are exactly the same', () => { | ||
const path1 = 'some-path/additional-path' | ||
const path2 = 'some-path/additional-path' | ||
const result = exactPathTest(path1, path2, basepath) | ||
expect(result).toBe(true) | ||
}) | ||
it('should return true when two paths are the same with or without trailing slash', () => { | ||
const path1 = 'some-path/additional-path' | ||
const path2 = 'some-path/additional-path/' | ||
const result = exactPathTest(path1, path2, basepath) | ||
expect(result).toBe(true) | ||
}) | ||
it('should return true when two paths are the same with or without trailing slash 2', () => { | ||
const path1 = 'some-path/additional-path' | ||
const path2 = 'some-path/additional-path/' | ||
const result = exactPathTest(path1, path2, basepath) | ||
expect(result).toBe(true) | ||
}) | ||
it('should return false when two paths are different', () => { | ||
const path1 = 'some-path/additional-path/' | ||
const path2 = 'some-path2/additional-path/' | ||
const result = exactPathTest(path1, path2, basepath) | ||
expect(result).toBe(false) | ||
}) | ||
it('should return true when both paths are just a slash', () => { | ||
const path1 = '/' | ||
const path2 = '/' | ||
const result = exactPathTest(path1, path2, basepath) | ||
expect(result).toBe(true) | ||
}) | ||
}, | ||
) |
Oops, something went wrong.