Skip to content

Commit 280a861

Browse files
committed
fix: Allow comment after top-level block scalar with explicit indent indicator (fixes #547)
1 parent 767bc47 commit 280a861

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/parse/lexer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ export class Lexer {
537537
if (!ch && !this.atEnd) return this.setNext('block-scalar')
538538
if (indent >= this.indentNext) {
539539
if (this.blockScalarIndent === -1) this.indentNext = indent
540-
else this.indentNext += this.blockScalarIndent
540+
else {
541+
this.indentNext =
542+
this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext)
543+
}
541544
do {
542545
const cs = this.continueScalar(nl + 1)
543546
if (cs === -1) break

tests/doc/parse.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ describe('maps with no values', () => {
412412
describe('odd indentations', () => {
413413
test('Block map with empty explicit key (#551)', () => {
414414
const doc = YAML.parseDocument<YAML.YAMLMap, false>('?\n? a')
415+
expect(doc.errors).toHaveLength(0)
415416
expect(doc.contents.items).toMatchObject([
416417
{ key: { value: null }, value: null },
417418
{ key: { value: 'a' }, value: null }
@@ -432,6 +433,12 @@ describe('odd indentations', () => {
432433
const doc = YAML.parseDocument<YAML.YAMLMap, false>('a:\n{x}')
433434
expect(doc.errors).not.toHaveLength(0)
434435
})
436+
437+
test('comment after top-level block scalar with indentation indicator (#547)', () => {
438+
const doc = YAML.parseDocument<YAML.Scalar, false>('|1\n x\n#c')
439+
expect(doc.errors).toHaveLength(0)
440+
expect(doc.contents).toMatchObject({ value: 'x\n' })
441+
})
435442
})
436443

437444
describe('Excessive entity expansion attacks', () => {

0 commit comments

Comments
 (0)