mirror of
https://github.com/adrienverge/yamllint.git
synced 2024-11-25 17:10:16 -06:00
key-duplicates: Don't crash on redundant closing brackets or braces
Don't break on empty `context` stack when invalid YAML: [ a, b, c ] ] {a: 1, b: 2} }
This commit is contained in:
parent
2f423117c1
commit
c268a82c5a
@ -87,6 +87,10 @@ class KeyDuplicatesTestCase(RuleTestCase):
|
|||||||
'anchor_reference:\n'
|
'anchor_reference:\n'
|
||||||
' <<: *anchor_one\n'
|
' <<: *anchor_one\n'
|
||||||
' <<: *anchor_two\n', conf)
|
' <<: *anchor_two\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'{a:1, b:2}}\n', conf, problem=(2, 11, 'syntax'))
|
||||||
|
self.check('---\n'
|
||||||
|
'[a, b, c]]\n', conf, problem=(2, 10, 'syntax'))
|
||||||
|
|
||||||
def test_enabled(self):
|
def test_enabled(self):
|
||||||
conf = 'key-duplicates: enable'
|
conf = 'key-duplicates: enable'
|
||||||
@ -165,6 +169,10 @@ class KeyDuplicatesTestCase(RuleTestCase):
|
|||||||
'anchor_reference:\n'
|
'anchor_reference:\n'
|
||||||
' <<: *anchor_one\n'
|
' <<: *anchor_one\n'
|
||||||
' <<: *anchor_two\n', conf)
|
' <<: *anchor_two\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'{a:1, b:2}}\n', conf, problem=(2, 11, 'syntax'))
|
||||||
|
self.check('---\n'
|
||||||
|
'[a, b, c]]\n', conf, problem=(2, 10, 'syntax'))
|
||||||
|
|
||||||
def test_key_tokens_in_flow_sequences(self):
|
def test_key_tokens_in_flow_sequences(self):
|
||||||
conf = 'key-duplicates: enable'
|
conf = 'key-duplicates: enable'
|
||||||
|
@ -84,7 +84,8 @@ def check(conf, token, prev, next, nextnext, context):
|
|||||||
elif isinstance(token, (yaml.BlockEndToken,
|
elif isinstance(token, (yaml.BlockEndToken,
|
||||||
yaml.FlowMappingEndToken,
|
yaml.FlowMappingEndToken,
|
||||||
yaml.FlowSequenceEndToken)):
|
yaml.FlowSequenceEndToken)):
|
||||||
context['stack'].pop()
|
if len(context['stack']) > 0:
|
||||||
|
context['stack'].pop()
|
||||||
elif (isinstance(token, yaml.KeyToken) and
|
elif (isinstance(token, yaml.KeyToken) and
|
||||||
isinstance(next, yaml.ScalarToken)):
|
isinstance(next, yaml.ScalarToken)):
|
||||||
# This check is done because KeyTokens can be found inside flow
|
# This check is done because KeyTokens can be found inside flow
|
||||||
|
Loading…
Reference in New Issue
Block a user