pyyaml icon indicating copy to clipboard operation
pyyaml copied to clipboard

`[\?]` fails to parse in `Loader` but works in `CLoader`

Open silverwind opened this issue 1 year ago • 3 comments

The string [\?] parses fine in CLoader while Loader fails to do so. Is it expected?

$ python3
Python 3.11.5 (main, Aug 24 2023, 15:18:16) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from yaml import load, CLoader, Loader
>>> load('[\?]', CLoader)
['\\?']
>>> load('[\?]', Loader)
...
  File "/usr/local/lib/python3.11/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yaml/parser.py", line 483, in parse_flow_sequence_entry
    raise ParserError("while parsing a flow sequence", self.marks[-1],
yaml.parser.ParserError: while parsing a flow sequence
  in "<unicode string>", line 1, column 1:
    [\?]
    ^
expected ',' or ']', but got '?'
  in "<unicode string>", line 1, column 3:
    [\?]
      ^

silverwind avatar Sep 08 '23 07:09 silverwind

duplicate of #128

perlpunk avatar Sep 08 '23 11:09 perlpunk

Okay, but shouldn't both loaders either fail or succeed in tandem?

silverwind avatar Sep 08 '23 11:09 silverwind

Ideally, yes, but it has to be implemented in both libyaml and pyyaml. First, the maintainers of pyyaml should be clear if they want that fix or not

perlpunk avatar Sep 08 '23 12:09 perlpunk