-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax Error (unexpected colon) for list containing a URL #86
Comments
this You can check several parsers with the yaml-runtimes containers, in several ways:
Or you can use the playground https://play.yaml.io/main/parser?input=W2N1cmwsIGh0dHBzOi8vZ2l0aHViLmNvbS9weWNvbnRyaWJzL3J1eWFtbC9pc3N1ZXMvbmV3XQ== A colon is only special if a whitespace is following (or if it is at the end of the line). This was also fixed in pyyaml and libyaml a while ago:
edit: btw, the YAML terminology for list is sequence, and the |
Thanks, I appreciate the extra background information! Looks like my issue was with the pre-commit >>> import ruamel.yaml
>>>
>>> yaml_str = "- repos:\n - command: [curl, https://github.com/pycontribs/ruyaml/issues/new]\n"
>>>
>>> yaml = ruamel.yaml.YAML(typ='safe')
>>> yaml_dict = yaml.load(yaml_str)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kyleking/Developer/wip/calcipy/.venv/lib/python3.10/site-packages/ruamel/yaml/main.py", line 434, in load
return constructor.get_single_data()
File "/Users/kyleking/Developer/wip/calcipy/.venv/lib/python3.10/site-packages/ruamel/yaml/constructor.py", line 119, in get_single_data
node = self.composer.get_single_node()
File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
File "_ruamel_yaml.pyx", line 773, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 850, in _ruamel_yaml.CParser._compose_sequence_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 773, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 850, in _ruamel_yaml.CParser._compose_sequence_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 773, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 852, in _ruamel_yaml.CParser._compose_sequence_node
File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: while scanning a plain scalar
in "<unicode string>", line 2, column 21
found unexpected ':'
in "<unicode string>", line 2, column 26
>>>
>>> yaml = ruamel.yaml.YAML(typ='safe')
>>> yaml_dicts = [*yaml.parse(yaml_str)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kyleking/Developer/wip/calcipy/.venv/lib/python3.10/site-packages/ruamel/yaml/main.py", line 348, in parse
while parser.check_event():
File "_ruamel_yaml.pyx", line 675, in _ruamel_yaml.CParser.check_event
File "_ruamel_yaml.pyx", line 529, in _ruamel_yaml.CParser._parse
ruamel.yaml.scanner.ScannerError: while scanning a plain scalar
in "<unicode string>", line 2, column 21
found unexpected ':'
in "<unicode string>", line 2, column 26
>>>
>>>
>>> # No error when not set to "safe"
>>> yaml = ruamel.yaml.YAML()
>>> yaml_dict = yaml.load(yaml_str)
>>> print(yaml_dict)
[ordereddict([('repos', [ordereddict([('command', ['curl', 'https://github.com/pycontribs/ruyaml/issues/new'])])])])]
>>> |
Just so future readers are aware,
|
I initially reported this issue here: lyz-code/yamlfix#161
But the root cause appears to be that
ruyaml
doesn't handle the edge case that certain characters (colons and possibly others?) need to be escaped within a list. A reproducible example is below:I'm not very familiar with the YAML spec and the
ruyaml
codebase, but I could take a look at contributing if someone could point me in the right directionThe text was updated successfully, but these errors were encountered: