diff --git a/packages/docusaurus-theme-common/src/utils/__tests__/pathUtils.test.ts b/packages/docusaurus-theme-common/src/utils/__tests__/pathUtils.test.ts index 71d88b7d9a..1e7d436a76 100644 --- a/packages/docusaurus-theme-common/src/utils/__tests__/pathUtils.test.ts +++ b/packages/docusaurus-theme-common/src/utils/__tests__/pathUtils.test.ts @@ -16,6 +16,14 @@ describe('isSamePath', () => { 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', () => { expect(isSamePath('/docs', '/docs//')).toBeFalsy(); }); diff --git a/packages/docusaurus-theme-common/src/utils/pathUtils.ts b/packages/docusaurus-theme-common/src/utils/pathUtils.ts index cde5ae1a06..9441add949 100644 --- a/packages/docusaurus-theme-common/src/utils/pathUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/pathUtils.ts @@ -5,12 +5,15 @@ * 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 = ( path1: string | undefined, path2: string | undefined, ): boolean => { const normalize = (pathname: string | undefined) => - !pathname || pathname?.endsWith('/') ? pathname : `${pathname}/`; + (!pathname || pathname?.endsWith('/') + ? pathname + : `${pathname}/` + )?.toLowerCase(); return normalize(path1) === normalize(path2); }; diff --git a/website/_dogfooding/_docs tests/tests/Case-Sentitive-Doc.md b/website/_dogfooding/_docs tests/tests/Case-Sentitive-Doc.md new file mode 100644 index 0000000000..58de34b32e --- /dev/null +++ b/website/_dogfooding/_docs tests/tests/Case-Sentitive-Doc.md @@ -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.