From 231d72aab8d34a2fd88aad8ff8bed1106c7ed164 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 11 Dec 2024 10:14:58 -0600 Subject: [PATCH] Fixes #3583 --- src/Plugins/InputPathToUrl.js | 7 +++-- test/InputPathToUrlPluginTest.js | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/Plugins/InputPathToUrl.js b/src/Plugins/InputPathToUrl.js index 952543bc0..aca148bf4 100644 --- a/src/Plugins/InputPathToUrl.js +++ b/src/Plugins/InputPathToUrl.js @@ -3,7 +3,8 @@ import { TemplatePath } from "@11ty/eleventy-utils"; import isValidUrl from "../Util/ValidUrl.js"; function getValidPath(contentMap, testPath) { - let normalized = TemplatePath.addLeadingDotSlash(testPath); + // if the path is coming from Markdown, it may be encoded + let normalized = TemplatePath.addLeadingDotSlash(decodeURIComponent(testPath)); // it must exist in the content map to be valid if (contentMap[normalized]) { @@ -68,8 +69,8 @@ function parseFilePath(filepath) { // Note that `node:url` -> pathToFileURL creates an absolute path, which we don’t want // URL(`file:#anchor`) gives back a pathname of `/` let u = new URL(`file:${filepath}`); - filepath = filepath.replace(u.search, ""); - filepath = filepath.replace(u.hash, ""); + filepath = filepath.replace(u.search, ""); // includes ? + filepath = filepath.replace(u.hash, ""); // includes # return [ // search includes ?, hash includes # diff --git a/test/InputPathToUrlPluginTest.js b/test/InputPathToUrlPluginTest.js index b42237910..29356c22b 100644 --- a/test/InputPathToUrlPluginTest.js +++ b/test/InputPathToUrlPluginTest.js @@ -190,3 +190,57 @@ test("Issue #3581 #build-cost-🧰", async (t) => { `Target` ); }); + +test("Issue #3583 Markdown diacritics", async (t) => { + let elev = new Eleventy("./test/stubs-virtual/", "./test/stubs-virtual/_site", { + configPath: false, + config: function (eleventyConfig) { + eleventyConfig.addTemplate("test.md", `[Target]()`) + }, + }); + + let results = await elev.toJSON(); + + t.is( + getContentFor(results, "/test/index.html"), + `

Target

` + ); +}); + +test("Issue #3583 Diacritics", async (t) => { + let elev = new Eleventy("./test/stubs-virtual/", "./test/stubs-virtual/_site", { + configPath: false, + config: function (eleventyConfig) { + eleventyConfig.addPlugin(TransformPlugin); + + eleventyConfig.addTemplate("test.md", `[Target](/hypothèse.md)`) + eleventyConfig.addTemplate("hypothèse.md", "lol") + }, + }); + + let results = await elev.toJSON(); + + t.is( + getContentFor(results, "/test/index.html"), + `

Target

` + ); +}); + +test("Issue #3583 Diacritics Markdown raw", async (t) => { + let elev = new Eleventy("./test/stubs-virtual/", "./test/stubs-virtual/_site", { + configPath: false, + config: function (eleventyConfig) { + eleventyConfig.addPlugin(TransformPlugin); + + eleventyConfig.addTemplate("test.md", `[Target]()`) + eleventyConfig.addTemplate("hypothèse.md", "lol") + }, + }); + + let results = await elev.toJSON(); + + t.is( + getContentFor(results, "/test/index.html"), + `

Target

` + ); +});