MaybeJustJames/yaml

Duplicated keys in record

Closed this issue · 2 comments

eapyl commented

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

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

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