You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(...) I don't have much bandwidth to actively provide support to the posted issues asking for new features or bugfixes that don't affect my own use cases of the library. If this situation is an issue for you, I suggest you use js-yaml which is a great and pretty feature-complete yaml parser and dumper for javascript.
But more importantly, we've encountered a number of real problems with jeremyfa/yaml.js in the Web IDE over time (more on that in following comments). So it has long been clear that it's time to switch to another library.
This is actually a pretty big deal, as replacement of this library means that we'll need to re-evaluate all the complaints about YAML parsing - like #63
Please at least put a note about this library change - what exactly is changing and why - into PR info.
Both libraries seem to be pretty solid, definitely better than jeremyfa/yaml.js that we've been using. They both solve many pain points of jeremyfa/yaml.js - I'll list below the issues solved by switching to either library.
This example also shows another problematic behavior of jeremyfa/yaml.js: duplicate keys are silently allowed (leading to data loss) instead of being rejected with an error.
Flow-style multi-line strings don't trigger a parse error and are parsed correctly as per the spec (i.e. single newlines should not translate to \n in the output string, a double newline is needed for this, see https://yaml-multiline.info/#flow-scalars-plain)
A mapping key-value pair of a mapping indented more than the previous one is considered an error, not included in the value of the previous key-value pair
Duplicate mapping keys are rejected with an error (this is the default behavior in both nodeca/js-yaml and eemeli/yaml), not silently allowed as in jeremyfa/yaml.js, where only the first entry is kept (i.e. resulting in a data loss, which tends to be surprising for many people that don't know this property of YAML)
So far we've been using jeremyfa/yaml.js to parse YAML in the Web IDE. However, it is more or less abandoned. Last release 0.3.0 was published on 2017-06-24 and there's a note at the top of its README that it is unlikely to receive new features or bugfixes (https://github.com/jeremyfa/yaml.js/tree/efe8ce18704ae43383e4177aa7de1a2619bd4e67#readme):
But more importantly, we've encountered a number of real problems with jeremyfa/yaml.js in the Web IDE over time (more on that in following comments). So it has long been clear that it's time to switch to another library.
As described at https://philna.sh/blog/2023/02/02/yaml-document-from-hell-javascript-edition/#yaml-in-javascript, there are 3 JavaScript libraries available for YAML parsing:
I wasn't sure whether option 2 or 3 would be a better choice, so I wanted to do some tests. Also, @GreyCat mentioned in https://github.com/kaitai-io/kaitai_struct_webide/pull/84/files#r276498978 that he'd want to make sure that the new YAML parsing library addresses the issues of the old one:
So I wrote a few scripts for testing and comparing the parsing results and put them in a repo: https://github.com/generalmimon/js-yaml-parsers-test
Both libraries seem to be pretty solid, definitely better than jeremyfa/yaml.js that we've been using. They both solve many pain points of jeremyfa/yaml.js - I'll list below the issues solved by switching to either library.
Legend to all diffs below:
No more broken hex literal parsing
Fixes YAML parser does not parse hex expressions correctly #63
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L6-L9)
Fixes Inconsistent hex literals in pos: kaitai_struct#456
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L11-L14)
No more parsing YAML 1.1 binary literals (
0b...) or YAML 1.2 octal literals (0o...) as0Fixes "unable to find enum member" when using binary notation #150
Details
This example also shows another problematic behavior of jeremyfa/yaml.js: duplicate keys are silently allowed (leading to data loss) instead of being rejected with an error.
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L16-L22)
https://yaml.org/spec/1.2.2/#example-integers
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L114-L120)
Flow-style multi-line strings don't trigger a parse error and are parsed correctly as per the spec (i.e. single newlines should not translate to
\nin the output string, a double newline is needed for this, see https://yaml-multiline.info/#flow-scalars-plain)Fixes YAML parser doesn't recognize flow-style multi-line strings #27
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L29-L33)
Also fixes the parse error with https://github.com/kaitai-io/kaitai_struct_formats/blob/acdf0733633568c68869af15846abaf1c0eaa59a/image/tga.ksy#L17-L21
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L35-L41)
A mapping key-value pair of a mapping indented more than the previous one is considered an error, not included in the value of the previous key-value pair
Fixes incorrect parsing of https://github.com/kaitai-io/kaitai_struct_tests/blob/7d7ecf076cc02c5032ec399655b7c3d50bde96ad/formats_err/yaml_1.ksy
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L138-L149)
The notorious colon
:as part of the ternary operator in an unquoted string is no longer allowed, which is consistent with the SnakeYAML library used in the JVM compiler (and it is in fact correct behavior according to the YAML spec, see https://matrix.yaml.info/details/ZCZ6.html and https://matrix.yaml.info/details/ZL4Z.html)https://doc.kaitai.io/user_guide.html#_ternary_if_then_else_operator
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L43-L54)
Duplicate mapping keys are rejected with an error (this is the default behavior in both nodeca/js-yaml and eemeli/yaml), not silently allowed as in jeremyfa/yaml.js, where only the first entry is kept (i.e. resulting in a data loss, which tends to be surprising for many people that don't know this property of YAML)
Details
(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L151-L170)
Note that this behavior has been suggested several times before:
In 0.9, the feature of treating duplicate keys as errors was enabled in SnakeYAML used in JVM compiler builds: Multiple type declarations behaviour kaitai_struct#641 (comment)
Comment lines do not suspend counting of line numbers displayed in error messages like they do in jeremyfa/yaml.js
Fixes Invalid line number while parsing YAML if comments are used #62
Details
JSON is accepted
Fixes KSY (YAML) parser support for JSON kaitai_struct#693
Details
{ "doc": "json test", "meta": { "id": "test", "endian": "le" }, "seq": [ { "id": "version", "contents": [1, 255, 255, 255], "doc": "4 - structure version" } ] }(see https://github.com/generalmimon/js-yaml-parsers-test/blob/662870c1c092b8092f458f8ad94c23b3ad62f93c/results-diffs/yamljs_vs_js-yaml.diff#L206-L242)