Skip to content
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

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

Open
jonathn opened this issue Jul 22, 2020 · 5 comments
Open

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

jonathn opened this issue Jul 22, 2020 · 5 comments

Comments

@jonathn
Copy link
Contributor

jonathn commented Jul 22, 2020

  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
Copy link
Collaborator

sjakobi commented Jul 22, 2020

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
Copy link
Collaborator

I have a pull request up to fix aeson-yaml here: clovyr/aeson-yaml#9

@paulrbr-fl
Copy link

paulrbr-fl commented Aug 14, 2020

Edit: moved the comment to clovyr/aeson-yaml#12

paulrbr-fl added a commit to paulrbr-fl/dhall-haskell that referenced this issue Aug 31, 2020
About
dhall-lang#1939 (comment)

With the current aeson-yaml version used in Dhall, a text value
containing a colon like this one: `Location: https://example.org` is
not quoted in the yaml representation:

```
> dhall-to-yaml <<< '{ headers = ["Location: https://example.org"] }'
headers:
  - Location: https://example.org
```

which is a bug as it doesn't represent the same data.
paulrbr-fl added a commit to paulrbr-fl/dhall-haskell that referenced this issue Aug 31, 2020
About
dhall-lang#1939 (comment)

With the current aeson-yaml version used in Dhall, a text value
containing a colon like this one: `Location: https://example.org` is
not quoted in the yaml representation:

```
> dhall-to-yaml <<< '{ headers = ["Location: https://example.org"] }'
headers:
  - Location: https://example.org
```

which is a bug as it doesn't represent the same data.
@lrworth
Copy link
Contributor

lrworth commented Jun 3, 2024

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
Copy link
Collaborator

winitzki commented Jun 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants