hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
374 stars 64 forks source link

Define "lexicographic sort" for map iteration purposes #1

Closed apparentlymart closed 6 years ago

apparentlymart commented 6 years ago

Currently the spec has the following to say about iterating objects/maps:

For object and map types, the key is the string attribute name or element key, and the value is the attribute or element value. The elements are visited in the order defined by a lexicographic sort of the attribute names or keys.

It doesn't currently state what exactly is being lexicographically sorted. The current implementation is sorting the normalized UTF-8 sequences, which likely produces a counter-intuitive result on the boundaries between the different UTF-8 length prefixes.

Should figure out what we really want to do here, specify it, and then implement it.

apparentlymart commented 6 years ago

On reflection, this is already fully defined because UTF-8 lexicographical sort is identical to the same sort by unicode codepoint.