Skip to content

Comment parsing failes to correctly resolve \r\n in skip_multiline_spacer #252

@andreaskeller96

Description

@andreaskeller96

If used on Windows, toml files often have \r\n at the end of a line. The parser handles this relatively well, however in skip_multiline_spacer it removes the \n at the end of a comment without checking for a \r before. This results in invalid toml files written to disk using std::ofstream on windows.

Proposed fix:
Change this line:
https://github.com/ToruNiina/toml11/blob/main/include/toml11/parser.hpp#L1858
To:

if(!comment.empty() && comment.back() == '\n')
{
    comment.pop_back();
    if (!comment.empty() && comment.back() == '\r')
        comment.pop_back();
}

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