Skip to content

Commit

Permalink
fix: Require indentation from block scalar header & flow collections …
Browse files Browse the repository at this point in the history
…in mapping values (#553)
  • Loading branch information
eemeli committed Jun 8, 2024
1 parent 5096f83 commit 767bc47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/parse/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/doc/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ describe('odd indentations', () => {
const doc = YAML.parseDocument<YAML.YAMLMap, false>('?\n!!null')
expect(doc.errors).not.toHaveLength(0)
})

test('unindented block scalar header in mapping value (#553)', () => {
const doc = YAML.parseDocument<YAML.YAMLMap, false>('a:\n|\n x')
expect(doc.errors).not.toHaveLength(0)
})

test('unindented flow collection in mapping value', () => {
const doc = YAML.parseDocument<YAML.YAMLMap, false>('a:\n{x}')
expect(doc.errors).not.toHaveLength(0)
})
})

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

0 comments on commit 767bc47

Please sign in to comment.