Skip to content

Commit

Permalink
Fixes #3583
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 11, 2024
1 parent ba1c228 commit 231d72a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Plugins/InputPathToUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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 #
Expand Down
54 changes: 54 additions & 0 deletions test/InputPathToUrlPluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,57 @@ test("Issue #3581 #build-cost-🧰", async (t) => {
`<a href="#built-cost-🧰">Target</a>`
);
});

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](</hypothèse/>)`)
},
});

let results = await elev.toJSON();

t.is(
getContentFor(results, "/test/index.html"),
`<p><a href="/hypoth%C3%A8se/">Target</a></p>`
);
});

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"),
`<p><a href="/hypothèse/">Target</a></p>`
);
});

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](</hypothèse.md>)`)
eleventyConfig.addTemplate("hypothèse.md", "lol")
},
});

let results = await elev.toJSON();

t.is(
getContentFor(results, "/test/index.html"),
`<p><a href="/hypothèse/">Target</a></p>`
);
});

0 comments on commit 231d72a

Please sign in to comment.