diff --git a/packages/docusaurus-utils/src/__tests__/globUtils.test.ts b/packages/docusaurus-utils/src/__tests__/globUtils.test.ts index c35e164920ba..e65837b4f565 100644 --- a/packages/docusaurus-utils/src/__tests__/globUtils.test.ts +++ b/packages/docusaurus-utils/src/__tests__/globUtils.test.ts @@ -113,4 +113,21 @@ describe('createAbsoluteFilePathMatcher', () => { `"createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=/bad/path/myDoc.md was not contained in any of the root folders: /_root/docs, /root/_docs/, /__test__/website/src"`, ); }); + + it('matches paths with overlapping paths', () => { + const overlapMatcher = createAbsoluteFilePathMatcher(GlobExcludeDefault, [ + '/root/docs', + '/root/versioned_docs/version-2.0.0', + '/root/versioned_docs/version-2.0.0-rc.1', + ]); + expect( + overlapMatcher('/root/versioned_docs/version-2.0.0-rc.1/_partial.mdx'), + ).toBe(true); + expect( + overlapMatcher('/root/versioned_docs/version-2.0.0/_partial.mdx'), + ).toBe(true); + expect( + overlapMatcher('/root/versioned_docs/version-2.0.0/no-partial.mdx'), + ).toBe(false); + }); }); diff --git a/packages/docusaurus-utils/src/globUtils.ts b/packages/docusaurus-utils/src/globUtils.ts index d95fa35b54be..b0520a2d89e7 100644 --- a/packages/docusaurus-utils/src/globUtils.ts +++ b/packages/docusaurus-utils/src/globUtils.ts @@ -9,6 +9,7 @@ import path from 'path'; import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby +import {addTrailingSlash} from './urlUtils'; /** A re-export of the globby instance. */ export {default as Globby} from 'globby'; @@ -68,7 +69,7 @@ export function createAbsoluteFilePathMatcher( function getRelativeFilePath(absoluteFilePath: string) { const rootFolder = rootFolders.find((folderPath) => - absoluteFilePath.startsWith(folderPath), + absoluteFilePath.startsWith(addTrailingSlash(folderPath)), ); if (!rootFolder) { throw new Error(