Skip to content

Commas seem optional in flow sequences - is this intended? #170

@ghost

Description

We noticed that:

new YamlReader("['a'b]").read();

would parse without error, returning a list with 2 strings, "a" and "b".

Other parsers (pyyaml, SnakeYAML) fail on parsing this, due to expecting a comma between entries.

This YAML specification https://yaml.org/spec/1.2.2/#flow-sequences states:

Flow sequence content is denoted by surrounding “[” and “]” characters.
...
Sequence entries are separated by a “,” character.

I found it surpising that this library allowed it and thought it worth an issue for discussion.

Running a few more tests, it doesn't seem to always work - so I expect allowing the above is a subtle bug. e.g.

        System.err.println(new YamlReader("['a'b]").read());
        System.err.println(new YamlReader("[a b c d]").read());
        System.err.println(new YamlReader("['a,b' c d]").read());
        System.err.println(new YamlReader("['a'b'c'd]").read());

outputs the following:

[a, b]
[a b c d]
[a,b, c d]
[a, b'c'd]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions