diff --git a/changelog_unreleased/html/18453.md b/changelog_unreleased/html/18453.md new file mode 100644 index 000000000..bb1e4f0d1 --- /dev/null +++ b/changelog_unreleased/html/18453.md @@ -0,0 +1,26 @@ +#### Fix a bug around unicode in front matter (#18453 by @seiyab) + + +```html + +--- +title: 😄 +--- + + + + +--- +title: 😄 +--- + + + +--- +title: 😄 +--- + + +``` diff --git a/src/main/front-matter/parse.js b/src/main/front-matter/parse.js index 187659371..43203b01d 100644 --- a/src/main/front-matter/parse.js +++ b/src/main/front-matter/parse.js @@ -106,7 +106,10 @@ function parse(text) { frontMatter, get content() { const { raw } = frontMatter; - return raw.replaceAll(/[^\n]/gu, " ") + text.slice(raw.length); + return ( + // eslint-disable-next-line require-unicode-regexp -- string length matters so intentionally not using unicode flag + raw.replaceAll(/[^\n]/g, " ") + text.slice(raw.length) + ); }, }; } diff --git a/tests/format/html/front-matter/__snapshots__/format.test.js.snap b/tests/format/html/front-matter/__snapshots__/format.test.js.snap index 1387c1c95..36488d2ae 100644 --- a/tests/format/html/front-matter/__snapshots__/format.test.js.snap +++ b/tests/format/html/front-matter/__snapshots__/format.test.js.snap @@ -116,3 +116,25 @@ Test abc. ================================================================================ `; + +exports[`unicode.html format 1`] = ` +====================================options===================================== +parsers: ["html"] +printWidth: 80 + | printWidth +=====================================input====================================== +--- +title: "ABC 漢字 🇯🇵" +--- + + + +=====================================output===================================== +--- +title: "ABC 漢字 🇯🇵" +--- + + + +================================================================================ +`; diff --git a/tests/format/html/front-matter/unicode.html b/tests/format/html/front-matter/unicode.html new file mode 100644 index 000000000..015484718 --- /dev/null +++ b/tests/format/html/front-matter/unicode.html @@ -0,0 +1,5 @@ +--- +title: "ABC 漢字 🇯🇵" +--- + + diff --git a/tests/format/markdown/front-matter/__snapshots__/format.test.js.snap b/tests/format/markdown/front-matter/__snapshots__/format.test.js.snap index 7434355e8..48af5cff3 100644 --- a/tests/format/markdown/front-matter/__snapshots__/format.test.js.snap +++ b/tests/format/markdown/front-matter/__snapshots__/format.test.js.snap @@ -79,3 +79,25 @@ text ================================================================================ `; + +exports[`unicode.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +--- +title: "ABC 漢字 🇯🇵" +--- + +## Retrospective + +=====================================output===================================== +--- +title: "ABC 漢字 🇯🇵" +--- + +## Retrospective + +================================================================================ +`; diff --git a/tests/format/markdown/front-matter/unicode.md b/tests/format/markdown/front-matter/unicode.md new file mode 100644 index 000000000..058b9f2f3 --- /dev/null +++ b/tests/format/markdown/front-matter/unicode.md @@ -0,0 +1,5 @@ +--- +title: "ABC 漢字 🇯🇵" +--- + +## Retrospective