yaml / pyyaml

Canonical source repository for PyYAML
MIT License
2.47k stars 507 forks source link

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

Open silverwind opened 10 months ago

silverwind commented 10 months ago

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:
    [\?]
      ^
perlpunk commented 10 months ago

duplicate of #128

silverwind commented 10 months ago

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

perlpunk commented 10 months ago

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