Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andreaskeller96 opened this issue Jul 8, 2024 · 3 comments

Comments

@andreaskeller96
Copy link

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();
}
@ToruNiina
Copy link
Owner

Good catch!
And your fix looks correct. Would you like to make a pull request? I will do some work in the next weekend, so I will wait until then.

@andreaskeller96
Copy link
Author

Just created a pull request, thank you for the fast answer!

@ToruNiina
Copy link
Owner

Thank you! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants