diff --git a/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md new file mode 100644 index 000000000000..4a8408ae2373 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md @@ -0,0 +1,4 @@ +# Placeholder + +This is a dummy file inside a directory with a dot in its name. +It exists to test that directory links with dots are not treated as file assets. diff --git a/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts index 29bcad267a10..f9a64d226909 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts @@ -267,4 +267,22 @@ describe('transformLinks plugin', () => { }); }); }); + + it('does not transform link to a directory with a dot in its name', async () => { + const result = await processContent( + `[link](../directory-with.dot/)`, + ); + expect(result).toMatchInlineSnapshot( + `"[link](../directory-with.dot/)"`, + ); + }); + + it('does not transform link to a directory with a dot (no trailing slash)', async () => { + const result = await processContent( + `[link](../directory-with.dot)`, + ); + expect(result).toMatchInlineSnapshot( + `"[link](../directory-with.dot)"`, + ); + }); }); diff --git a/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts b/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts index 192c1e9f8cee..19bde36fa76c 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts @@ -229,6 +229,13 @@ async function processLinkNode(target: Target, context: Context) { ); if (localFilePath) { + // Skip asset transformation for directories (e.g., "directory-with.dot/") + // A directory path with a dot can match hasAssetLikeExtension, but it + // should not be treated as a file asset — it's a valid link target. + const stats = await fs.stat(localFilePath); + if (stats.isDirectory()) { + return; + } await toAssetRequireNode(target, localFilePath, context); } else { // The @site alias is the only way to believe that the user wants an asset.