Skip to content

Commit b1d2b28

Browse files
committed
Allow for empty lines after node props (Fixes #242)
1 parent 3e5a640 commit b1d2b28

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/cst/ParseContext.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ export class ParseContext {
125125
ch === '\n'
126126
) {
127127
if (ch === '\n') {
128-
const lineStart = offset + 1
129-
const inEnd = Node.endOfIndent(src, lineStart)
128+
let inEnd = offset
129+
let lineStart
130+
do {
131+
lineStart = inEnd + 1
132+
inEnd = Node.endOfIndent(src, lineStart)
133+
} while (src[inEnd] === '\n')
130134
const indentDiff = inEnd - (lineStart + this.indent)
131135
const noIndicatorAsIndent =
132136
parent.type === Type.SEQ_ITEM && parent.context.atLineStart

tests/doc/parse.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,47 @@ describe('maps with no values', () => {
466466
})
467467
})
468468

469+
describe('collection item with anchor followed by empty line (#242)', () => {
470+
test('reported 1', () => {
471+
const src = `
472+
key1: &default
473+
474+
subkey1: value1
475+
476+
key2:
477+
<<: *default\n`
478+
expect(YAML.parse(src, { merge: true })).toMatchObject({
479+
key1: { subkey1: 'value1' },
480+
key2: { subkey1: 'value1' }
481+
})
482+
})
483+
484+
test('reported 2', () => {
485+
const src = `
486+
key1: &default
487+
488+
# This key ...
489+
subkey1: value1
490+
491+
key2:
492+
<<: *default\n`
493+
expect(YAML.parse(src, { merge: true })).toMatchObject({
494+
key1: { subkey1: 'value1' },
495+
key2: { subkey1: 'value1' }
496+
})
497+
})
498+
499+
test('minimal with anchor', () => {
500+
const src = '- &a\n\n foo'
501+
expect(YAML.parse(src)).toMatchObject(['foo'])
502+
})
503+
504+
test('minimal with tag', () => {
505+
const src = '- !!str\n\n foo'
506+
expect(YAML.parse(src)).toMatchObject(['foo'])
507+
})
508+
})
509+
469510
describe('Excessive entity expansion attacks', () => {
470511
const root = path.resolve(__dirname, '../artifacts/pr104')
471512
const src1 = fs.readFileSync(path.resolve(root, 'case1.yml'), 'utf8')

0 commit comments

Comments
 (0)