Skip to content

Do not quote plain scalars with '-' symbol #354

@dbarkar

Description

@dbarkar

Please reconsider current rules for quoting scalars:

const bool needs_quotes = (
    was_quoted
    ||
    (
        ( ! s.is_number())
        &&
        (
            // has leading whitespace
            s.begins_with_any(" \n\t\r")
            ||
            // looks like reference or anchor or would be treated as a directive
            s.begins_with_any("*&%")
            ||
            s.begins_with("<<")
            ||
            // has trailing whitespace
            s.ends_with_any(" \n\t\r")
            ||
            // has special chars
            (s.first_of("#:-?,\n{}[]'\"") != npos)
        )
    )
);

List of escaped characters: https://yaml.org/spec/1.2.2/#57-escaped-characters
Plain scalar type: https://yaml.org/spec/1.2.2/#733-plain-style
At least, strings with '-' should not be quoted, there are even examples with such strings in standard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions