Skip to content

Commit de8a0ab

Browse files
Shruti157Shruti
andauthored
fix: Preserve empty block literals (#634)
Co-authored-by: Shruti <smittal4@opentext.com>
1 parent 81eb3bf commit de8a0ab

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/stringify/stringifyString.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function blockString(
186186
const { blockQuote, commentString, lineWidth } = ctx.options
187187
// 1. Block can't end in whitespace unless the last line is non-empty.
188188
// 2. Strings consisting of only whitespace are best rendered explicitly.
189-
if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
189+
if (!blockQuote || /\n[\t ]+$/.test(value)) {
190190
return quotedString(value, ctx)
191191
}
192192

tests/doc/stringify.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ blah blah\n`)
186186
.map(line => line.length)
187187
).toMatchObject([4, 20, 20, 20, 20, 10, 0])
188188
})
189+
190+
test('Keep pipe when empty block literal is given', () => {
191+
const doc = YAML.parseDocument('|-')
192+
expect(String(doc)).toBe('|\n\n')
193+
})
194+
195+
test('Keep pipe when pipe is provided', () => {
196+
const doc = YAML.parseDocument('|')
197+
expect(String(doc)).toBe('|\n\n')
198+
})
189199
})
190200
})
191201
}

0 commit comments

Comments
 (0)