mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 06:42:31 +02:00
fix(theme-common): isSamePath should be case-insensitive (#6758)
This commit is contained in:
parent
39b66d82ef
commit
44a65f3337
3 changed files with 18 additions and 2 deletions
|
@ -16,6 +16,14 @@ describe('isSamePath', () => {
|
||||||
expect(isSamePath('/docs', '/docs/')).toBeTruthy();
|
expect(isSamePath('/docs', '/docs/')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should be true for compared path with different case', () => {
|
||||||
|
expect(isSamePath('/doCS', '/DOcs')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should be true for compared path with different case + trailing slash', () => {
|
||||||
|
expect(isSamePath('/doCS', '/DOcs/')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
test('should be false for compared path with double trailing slash', () => {
|
test('should be false for compared path with double trailing slash', () => {
|
||||||
expect(isSamePath('/docs', '/docs//')).toBeFalsy();
|
expect(isSamePath('/docs', '/docs//')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,12 +5,15 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Compare the 2 paths, ignoring trailing /
|
// Compare the 2 paths, case insensitive and ignoring trailing slash
|
||||||
export const isSamePath = (
|
export const isSamePath = (
|
||||||
path1: string | undefined,
|
path1: string | undefined,
|
||||||
path2: string | undefined,
|
path2: string | undefined,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const normalize = (pathname: string | undefined) =>
|
const normalize = (pathname: string | undefined) =>
|
||||||
!pathname || pathname?.endsWith('/') ? pathname : `${pathname}/`;
|
(!pathname || pathname?.endsWith('/')
|
||||||
|
? pathname
|
||||||
|
: `${pathname}/`
|
||||||
|
)?.toLowerCase();
|
||||||
return normalize(path1) === normalize(path2);
|
return normalize(path1) === normalize(path2);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Case-Sensitive doc
|
||||||
|
|
||||||
|
This doc has uppercase and lowercase chars in its filename, and thus in its path / slug.
|
||||||
|
|
||||||
|
It should still work fine if the doc is server from a lowercase/uppercase path.
|
Loading…
Add table
Add a link
Reference in a new issue