diff --git a/changelog_unreleased/yaml/12305.md b/changelog_unreleased/yaml/12305.md new file mode 100644 index 000000000..f989c6157 --- /dev/null +++ b/changelog_unreleased/yaml/12305.md @@ -0,0 +1,15 @@ +#### Fix unexpected deletion of block-literal lines which starts with U+3000 (#12305 by @Quramy) + + +```yaml +# Input +block_with_ideographic_space: | +  line-content # This line starts with U+3000 + +# Prettier stable +block_with_ideographic_space: | + +// Prettier main +block_with_ideographic_space: | +  line-content # This line starts with U+3000 +``` diff --git a/src/language-yaml/utils.js b/src/language-yaml/utils.js index 82a4a354f..b1fde2d26 100644 --- a/src/language-yaml/utils.js +++ b/src/language-yaml/utils.js @@ -256,7 +256,7 @@ function getBlockValueLineContents( const leadingSpaceCount = node.indent === null ? ((match) => (match ? match[1].length : Number.POSITIVE_INFINITY))( - content.match(/^( *)\S/m) + content.match(/^( *)[^\n\r ]/m) ) : node.indent - 1 + parentIndent; diff --git a/tests/format/yaml/block-literal/jsfmt.spec.js b/tests/format/yaml/block-literal/jsfmt.spec.js index bedc8dbb9..0c58d7617 100644 --- a/tests/format/yaml/block-literal/jsfmt.spec.js +++ b/tests/format/yaml/block-literal/jsfmt.spec.js @@ -1,2 +1,17 @@ -run_spec(__dirname, ["yaml"]); -run_spec(__dirname, ["yaml"], { proseWrap: "always" }); +const { outdent } = require("outdent"); + +const snippets = [ + { + code: outdent` + block_with_ideographic_space: | + \u{3000}x + `, + output: outdent` + block_with_ideographic_space: | + \u{3000}x + `, + }, +].map((test) => ({ ...test, output: test.output + "\n" })); + +run_spec({ dirname: __dirname, snippets }, ["yaml"]); +run_spec({ dirname: __dirname, snippets }, ["yaml"], { proseWrap: "always" });