Skip to content

Commit

Permalink
Check for tags & anchors on sequence items before the - indicator (SY6V)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Feb 22, 2018
1 parent 22e4f65 commit 93a8a44
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion __tests__/yaml-test-suite.js
Expand Up @@ -24,7 +24,6 @@ const skipErrors = [
'9C9N',
'9KBC',
'B63P',
'SY6V',
'ZCZ6',
'ZL4Z',
]
Expand Down
10 changes: 10 additions & 0 deletions src/ast/Node.js
Expand Up @@ -210,6 +210,16 @@ export default class Node {
return false
}

get hasProps () {
if (this.context) {
const { src } = this.context
for (let i = 0; i < this.props.length; ++i) {
if (src[this.props[i].start] !== Char.COMMENT) return true
}
}
return false
}

get jsonLike () {
const jsonLikeTypes = [
Type.FLOW_MAP,
Expand Down
4 changes: 2 additions & 2 deletions src/ast/ParseContext.js
Expand Up @@ -111,8 +111,8 @@ export default class ParseContext {
}
ch = src[offset]
}
// '- &a : b' has an anchor on an empty PLAIN node
if (lineHasProps && Node.atCollectionItem(src, offset)) offset -= 1
// '- &a : b' has an anchor on an empty node
if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1)) offset -= 1
const type = ParseContext.parseType(src, offset, inFlow)
trace: 'props', type, { props, offset }
return { props, type, valueStart: offset }
Expand Down
2 changes: 2 additions & 0 deletions src/schema/Seq.js
Expand Up @@ -23,6 +23,8 @@ export default class YAMLSeq extends Collection {
break
case Type.SEQ_ITEM:
this.items.push(doc.resolveNode(item.node))
if (item.hasProps) doc.errors.push(new YAMLSyntaxError(item,
'Sequence items cannot have tags or anchors before the - indicator'))
break
default:
doc.errors.push(new YAMLSyntaxError(item,
Expand Down

0 comments on commit 93a8a44

Please sign in to comment.