diff --git a/src/parse/parser.ts b/src/parse/parser.ts index af09b527..3c26577e 100644 --- a/src/parse/parser.ts +++ b/src/parse/parser.ts @@ -529,9 +529,9 @@ export class Parser { } if (this.indent >= map.indent) { + const atMapIndent = !this.onKeyLine && this.indent === map.indent const atNextItem = - !this.onKeyLine && - this.indent === map.indent && + atMapIndent && (it.sep || it.explicitKey) && this.type !== 'seq-item-ind' @@ -673,7 +673,7 @@ export class Parser { default: { const bv = this.startBlockValue(map) if (bv) { - if (atNextItem && bv.type !== 'block-seq' && it.explicitKey) { + if (atMapIndent && bv.type !== 'block-seq') { map.items.push({ start }) } this.stack.push(bv) diff --git a/tests/doc/parse.ts b/tests/doc/parse.ts index a6af6764..154db795 100644 --- a/tests/doc/parse.ts +++ b/tests/doc/parse.ts @@ -422,6 +422,16 @@ describe('odd indentations', () => { const doc = YAML.parseDocument('?\n!!null') expect(doc.errors).not.toHaveLength(0) }) + + test('unindented block scalar header in mapping value (#553)', () => { + const doc = YAML.parseDocument('a:\n|\n x') + expect(doc.errors).not.toHaveLength(0) + }) + + test('unindented flow collection in mapping value', () => { + const doc = YAML.parseDocument('a:\n{x}') + expect(doc.errors).not.toHaveLength(0) + }) }) describe('Excessive entity expansion attacks', () => {