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:
Jérôme Alet
2022-04-20 20:00:08 +11:00
committed by GitHub
parent 2f423117c1
commit c268a82c5a
2 changed files with 10 additions and 1 deletions

View File

@@ -84,7 +84,8 @@ def check(conf, token, prev, next, nextnext, context):
elif isinstance(token, (yaml.BlockEndToken,
yaml.FlowMappingEndToken,
yaml.FlowSequenceEndToken)):
context['stack'].pop()
if len(context['stack']) > 0:
context['stack'].pop()
elif (isinstance(token, yaml.KeyToken) and
isinstance(next, yaml.ScalarToken)):
# This check is done because KeyTokens can be found inside flow