fix(line-length): Wrap token scanning securely
With `allow-non-breakable-inline-mappings` enabled, every long line is passed through `loader.peek_token()`. Even lines that are not valid YAML. For this reason, this code must be wrapped in a `try`/`except` block. Closes: #21
This commit is contained in:
@@ -102,13 +102,18 @@ CONF = {'max': int,
|
||||
|
||||
def check_inline_mapping(line):
|
||||
loader = yaml.SafeLoader(line.content)
|
||||
while loader.peek_token():
|
||||
if isinstance(loader.get_token(), yaml.BlockMappingStartToken):
|
||||
while loader.peek_token():
|
||||
if isinstance(loader.get_token(), yaml.ValueToken):
|
||||
t = loader.get_token()
|
||||
if isinstance(t, yaml.ScalarToken):
|
||||
return ' ' not in line.content[t.start_mark.column:]
|
||||
try:
|
||||
while loader.peek_token():
|
||||
if isinstance(loader.get_token(), yaml.BlockMappingStartToken):
|
||||
while loader.peek_token():
|
||||
if isinstance(loader.get_token(), yaml.ValueToken):
|
||||
t = loader.get_token()
|
||||
if isinstance(t, yaml.ScalarToken):
|
||||
return (
|
||||
' ' not in line.content[t.start_mark.column:])
|
||||
except yaml.scanner.ScannerError:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user