MaybeJustJames / yaml

Work with YAML in Elm.
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

Duplicated keys in record #24

Closed eapyl closed 2 years ago

eapyl commented 2 years ago

Hello,

It seems like the library ignores duplicated keys silently

root:
  item1:
    name: Item1
  item1:
    name: Item 2

and it seems like cause Dict.fromList is used on the list without duplication check. Is it expected behavior? It feels for me that it should produce an error in such cases. Or am I wrong? Thanks

MaybeJustJames commented 2 years ago

Hi @eapyl Indeed you are right. I'm following pyyaml behaviour here but, as pointed out in this bug, the yaml spec says keys should be unique.

The problem should probably be caught earlier, in the parsing step (e.g. https://github.com/MaybeJustJames/yaml/blob/2.1.0/src/Yaml/Parser.elm#L454) since, at decode time, we no longer know there are duplicate keys.

I would gladly accept a PR for this because I probably won't be able to fix this in the near term

ypyl commented 2 years ago

Hello @MaybeJustJames, thank you for pointing out the source code where it can be fixed. I have prepared a small PR. Could you please check it and comment? thanks