Open stealthybox opened 7 years ago
This is an edge case. The spec is not very clear on that. @flyx mentioned that he had been asking about that on the mailing list two years ago: https://sourceforge.net/p/yaml/mailman/message/34909032/
I would generally add a space after an alias key to make sure it's portable. It should also be noted that libyaml and pyyaml do not support :
anywhere in aliases/anchors.
When playing with that, it seems I found a bug in libyaml, pyyaml and snakeyaml:
foo: &a:b bar
is parsed the same as foo: &a :b bar
So I would avoid :
in aliases completely.
@perlpunk In personal experience, I have not seen other usage in which people add spaces after their aliases to mitigate this problem, but it's good advice for compat /w this version of js-yaml.
I agree about disallowing :
in aliases in the tokenizer.
Since the spec is so lax on this point, it's probably a source of implementation specific divergences like you discovered.
Neat find!
js-yaml: @3.7.0 Node v7.2.1 Windows 10 Pro
disclaimer: I'm not an expert on the YAML spec
the bug
"
:
" is a valid character when defining anchors and using aliases. It is valid to use aliases as keys."
:
" is also used to denote a node. This seems to cause a bug where you are unable to use aliases as keys unless you separate the alias from the ":
" with whitespace.Trailing "
:
"'s look like they're being included in the alias token by the while loop inloader.readAlias()
. I don't know the code very well, but a fix might need some extra logic inloader.composeNode()
.some tests
output