Skip to content

Commit

Permalink
fix: Do not require quotes for implicit keys with flow indicators (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Aug 28, 2023
1 parent 07063bc commit 9558e96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stringify/stringifyString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function plainString(
const { type, value } = item
const { actualString, implicitKey, indent, indentStep, inFlow } = ctx
if (
(implicitKey && /[\n[\]{},]/.test(value)) ||
(implicitKey && value.includes('\n')) ||
(inFlow && /[[\]{},]/.test(value))
) {
return quotedString(value, ctx)
Expand Down
5 changes: 5 additions & 0 deletions tests/doc/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ z:
expect(String(doc)).toBe('a: 1\n? b: 2\n c: 3\n')
})

test('plain key containing flow indicators', () => {
const doc = YAML.parseDocument('foo[{}]: bar')
expect(doc.toString()).toBe('foo[{}]: bar\n')
})

describe('No extra whitespace for empty values', () => {
const getDoc = () =>
new YAML.Document<YAML.YAMLMap<YAML.Scalar, YAML.Scalar>, false>({
Expand Down

0 comments on commit 9558e96

Please sign in to comment.