Skip to content

Commit 767bc47

Browse files
committed
fix: Require indentation from block scalar header & flow collections in mapping values (#553)
1 parent 5096f83 commit 767bc47

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/parse/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ export class Parser {
529529
}
530530

531531
if (this.indent >= map.indent) {
532+
const atMapIndent = !this.onKeyLine && this.indent === map.indent
532533
const atNextItem =
533-
!this.onKeyLine &&
534-
this.indent === map.indent &&
534+
atMapIndent &&
535535
(it.sep || it.explicitKey) &&
536536
this.type !== 'seq-item-ind'
537537

@@ -673,7 +673,7 @@ export class Parser {
673673
default: {
674674
const bv = this.startBlockValue(map)
675675
if (bv) {
676-
if (atNextItem && bv.type !== 'block-seq' && it.explicitKey) {
676+
if (atMapIndent && bv.type !== 'block-seq') {
677677
map.items.push({ start })
678678
}
679679
this.stack.push(bv)

tests/doc/parse.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ describe('odd indentations', () => {
422422
const doc = YAML.parseDocument<YAML.YAMLMap, false>('?\n!!null')
423423
expect(doc.errors).not.toHaveLength(0)
424424
})
425+
426+
test('unindented block scalar header in mapping value (#553)', () => {
427+
const doc = YAML.parseDocument<YAML.YAMLMap, false>('a:\n|\n x')
428+
expect(doc.errors).not.toHaveLength(0)
429+
})
430+
431+
test('unindented flow collection in mapping value', () => {
432+
const doc = YAML.parseDocument<YAML.YAMLMap, false>('a:\n{x}')
433+
expect(doc.errors).not.toHaveLength(0)
434+
})
425435
})
426436

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

0 commit comments

Comments
 (0)