dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
909 stars 211 forks source link

dhall-to-yaml faulty output corner cases? #1939

Open jonathn opened 3 years ago

jonathn commented 3 years ago
  1. dhall-to-yaml doesn't quote string scalars ending in : (breaks some yaml parsers).
  2. dhall-to-yaml doesn't quote string keys or string scalars ending in space.
  3. dhall-to-yaml unnecessarily quotes keys consisting of one or more letter e.

I don't think the --quoted option should be required to avoid the weirdness.

$ dhall-to-yaml --version
1.7.0

$ dhall-to-yaml <<< '{ pp = "one:", qq = "one: ", rr = ":two", ss = "one:two", tt = "one two", uu = "1", vv = 1 }'
pp: one:
qq: one:
rr: ":two"
ss: one:two
tt: one two
uu: '1'
vv: 1
$ dhall-to-yaml <<< '{ pp = "one:", qq = "one: ", rr = ":two", ss = "one:two", tt = "one two", uu = "1", vv = 1 }' | python -c 'import sys; import yaml; print(yaml.safe_load(sys.stdin))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/__init__.py", line 162, in safe_load
    return load(stream, SafeLoader)
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/scanner.py", line 116, in check_token
    self.fetch_more_tokens()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/scanner.py", line 223, in fetch_more_tokens
    return self.fetch_value()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/scanner.py", line 579, in fetch_value
    self.get_mark())
yaml.scanner.ScannerError: mapping values are not allowed here
  in "<stdin>", line 1, column 8

$ dhall-to-yaml <<< '{ `pp ` = "one " }'
pp : one
$ dhall-to-yaml <<< '{ `pp ` = "one " }' | python -c 'import sys; import yaml; print(yaml.safe_load(sys.stdin))'
{'pp': 'one'}

$ dhall-to-yaml <<< '{ d = 1, dd = 1, e = 1, ee = 1, eee = 1, f = 1, ff = 1 }'
d: 1
dd: 1
'e': 1
'ee': 1
'eee': 1
f: 1
ff: 1
sjakobi commented 3 years ago

Thanks for the report! I think all of these issues stem from the YAML renderer used in dhall-to-yaml, which is aeson-yaml. Could you pass this on?

As a workaround, you could try using an alternative Dhall to YAML converter, dhall-to-yaml-ng from the dhall-yaml package, that might handle these cases better.

Gabriella439 commented 3 years ago

I have a pull request up to fix aeson-yaml here: https://github.com/clovyr/aeson-yaml/pull/9

paulrbr-fl commented 3 years ago

Edit: moved the comment to https://github.com/clovyr/aeson-yaml/issues/12

lrworth commented 1 month ago

https://github.com/clovyr/aeson-yaml seems to be unmaintained and dhall-json still produces broken YAML.

Since dhall-yaml seems to do a better job anyway, should dhall-json just drop support for YAML?

winitzki commented 1 month ago

A question: is there a complete specification for what dhall-yaml must do, and tests checking that dhall-to-yaml agrees with that specification?