Skip to content

Commit

Permalink
cst: Stop breaking the spec by allowing tab indents for map values
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Dec 27, 2018
1 parent 94ebaa2 commit 572f540
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions __tests__/corner-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,12 @@ test('parse an empty string as null', () => {
const value = YAML.parse('')
expect(value).toBeNull()
})

test('fail on map value indented with tab', () => {
const src = 'a:\n\t1\nb:\n\t2\n'
const doc = YAML.parseDocument(src)
expect(doc.errors).toMatchObject([
{ name: 'YAMLSemanticError' },
{ name: 'YAMLSemanticError' }
])
})
7 changes: 3 additions & 4 deletions src/cst/CollectionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ export default class CollectionItem extends Node {
let offset = Node.endOfWhiteSpace(src, start + 1)
let ch = src[offset]
while (ch === '\n' || ch === '#') {
const next = offset + 1
if (ch === '#') {
const end = Node.endOfLine(src, next)
const end = Node.endOfLine(src, offset + 1)
this.props.push(new Range(offset, end))
offset = end
} else {
atLineStart = true
lineStart = next
offset = Node.endOfWhiteSpace(src, next) // against spec, to match \t allowed after indicator
lineStart = offset + 1
offset = Node.endOfIndent(src, lineStart)
}
ch = src[offset]
}
Expand Down

0 comments on commit 572f540

Please sign in to comment.