Option to enforce unique map keys
Mark Laff <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <CAAOnaRk8K4P3sWboYL+kgYex9Y-=LF06ihZoK=ML83RJ+FRZJQ@mail.gmail.com> |
While the YAML spec specifies that Mapping node keys must be unique [1.2
spec, section 3.2.1.1 Nodes], it seems like duplicate keys are not flagged.
For example:
a: 1
a: 2
->
%YAML 1.1
--- {a: 2}
...
While it is nice to be forgiving, there are applications in which errors
like this _must_ be flagged.
I suggest adding an option to the Yaml parser to
"allowDuplicateKeys(Boolean: duplicateKeysAllowed)" with a default of
"true". This default would continue to provide the current (forgiving)
behavior.
If, however, it matters, you would turn on the checking option and catch
the exception, e.g. (in SnakeYaml):
Yaml yaml = new Yaml();
yaml.allowDuplicateKeys(false);
String document = "a: 1\na: 2\n";
try
{
data = yaml.load(document);
} catch (DuplicateKeyYAMLException e)
{
// handle duplicate keys
System.out.println(e.toString());
}
where DuplicateKeyYAMLException extends MarkedYAMLException
In my application I would like to be sensitive to errors the the YAML my
users create, and detecting duplicate keys would be a valuable function.
Thoughts?
Mark
--
Mark Laff
[email protected]
914-262-0419 [mobile]
914-232-1020 [home office]
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core