Skip to content

Commit

Permalink
fix: Allow comment after top-level block scalar with explicit indent …
Browse files Browse the repository at this point in the history
…indicator (fixes #547)
  • Loading branch information
eemeli committed Jun 8, 2024
1 parent 767bc47 commit 280a861
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/parse/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ export class Lexer {
if (!ch && !this.atEnd) return this.setNext('block-scalar')
if (indent >= this.indentNext) {
if (this.blockScalarIndent === -1) this.indentNext = indent
else this.indentNext += this.blockScalarIndent
else {
this.indentNext =
this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext)
}
do {
const cs = this.continueScalar(nl + 1)
if (cs === -1) break
Expand Down
7 changes: 7 additions & 0 deletions tests/doc/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ describe('maps with no values', () => {
describe('odd indentations', () => {
test('Block map with empty explicit key (#551)', () => {
const doc = YAML.parseDocument<YAML.YAMLMap, false>('?\n? a')
expect(doc.errors).toHaveLength(0)
expect(doc.contents.items).toMatchObject([
{ key: { value: null }, value: null },
{ key: { value: 'a' }, value: null }
Expand All @@ -432,6 +433,12 @@ describe('odd indentations', () => {
const doc = YAML.parseDocument<YAML.YAMLMap, false>('a:\n{x}')
expect(doc.errors).not.toHaveLength(0)
})

test('comment after top-level block scalar with indentation indicator (#547)', () => {
const doc = YAML.parseDocument<YAML.Scalar, false>('|1\n x\n#c')
expect(doc.errors).toHaveLength(0)
expect(doc.contents).toMatchObject({ value: 'x\n' })
})
})

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

0 comments on commit 280a861

Please sign in to comment.