Skip to content

Commit

Permalink
Allow for empty lines after node props (Fixes #242)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Mar 13, 2021
1 parent 3e5a640 commit b1d2b28
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cst/ParseContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ export class ParseContext {
ch === '\n'
) {
if (ch === '\n') {
const lineStart = offset + 1
const inEnd = Node.endOfIndent(src, lineStart)
let inEnd = offset
let lineStart
do {
lineStart = inEnd + 1
inEnd = Node.endOfIndent(src, lineStart)
} while (src[inEnd] === '\n')
const indentDiff = inEnd - (lineStart + this.indent)
const noIndicatorAsIndent =
parent.type === Type.SEQ_ITEM && parent.context.atLineStart
Expand Down
41 changes: 41 additions & 0 deletions tests/doc/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,47 @@ describe('maps with no values', () => {
})
})

describe('collection item with anchor followed by empty line (#242)', () => {
test('reported 1', () => {
const src = `
key1: &default
subkey1: value1
key2:
<<: *default\n`
expect(YAML.parse(src, { merge: true })).toMatchObject({
key1: { subkey1: 'value1' },
key2: { subkey1: 'value1' }
})
})

test('reported 2', () => {
const src = `
key1: &default
# This key ...
subkey1: value1
key2:
<<: *default\n`
expect(YAML.parse(src, { merge: true })).toMatchObject({
key1: { subkey1: 'value1' },
key2: { subkey1: 'value1' }
})
})

test('minimal with anchor', () => {
const src = '- &a\n\n foo'
expect(YAML.parse(src)).toMatchObject(['foo'])
})

test('minimal with tag', () => {
const src = '- !!str\n\n foo'
expect(YAML.parse(src)).toMatchObject(['foo'])
})
})

describe('Excessive entity expansion attacks', () => {
const root = path.resolve(__dirname, '../artifacts/pr104')
const src1 = fs.readFileSync(path.resolve(root, 'case1.yml'), 'utf8')
Expand Down

0 comments on commit b1d2b28

Please sign in to comment.