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

ignore_comment=true fails on multiple consecutive lines starting with comments #2330

Closed
3 tasks
mattbement opened this issue Jul 31, 2020 · 6 comments · Fixed by #2332
Closed
3 tasks

ignore_comment=true fails on multiple consecutive lines starting with comments #2330

mattbement opened this issue Jul 31, 2020 · 6 comments · Fixed by #2332
Assignees
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@mattbement
Copy link

I know comments are not supported in json, but I'm trying to migrate a project that used YAJL, which has an option for allowing comments, specifically multiple consecutive lines of comments:

// description
// more description
{
...
}

I'm using the parse(...,ignore_comments=true) option, but it's failing on the second comment line. I

What is the issue you have?

Please describe the steps to reproduce the issue.

std::string ss = "//\n//\n{\n}\n";
json j = json::parse(ss,nullptr,true,true);

Can you provide a small but working code example?

std::string ss = "//\n//\n{\n}\n";
json j = json::parse(ss,nullptr,true,true);

What is the expected behavior?

should ignore both lines

And what is the actual behavior instead?

terminate called after throwing an instance of 'nlohmann::detail::parse_error'
what(): [json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - invalid literal; last read: '//<U+000A>/'
Aborted (core dumped)

Which compiler and operating system are you using?

  • Compiler: gcc 9.2
  • Operating system: Ubuntu 20.04

Which version of the library did you use?

  • latest release version 3.9.0
  • other release - please state the version: ___
  • [x ] the develop branch (35daa5c)

If you experience a compilation error: can you compile and run the unit tests?

  • [x ] yes
  • no - please copy/paste the error message below
@nlohmann
Copy link
Owner

The library does not skip comments inside strings, but only "between" JSON values, like around commas, colons, etc.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Jul 31, 2020
@mattbement
Copy link
Author

mattbement commented Jul 31, 2020

Understood, but this isn't within strings. This is multiple lines of comments at the very beginning of a file, before the first {

@nlohmann
Copy link
Owner

Oh, I see. Will check tonight.

@nlohmann nlohmann added confirmed kind: bug and removed solution: invalid the issue is not related to the library labels Jul 31, 2020
@nlohmann nlohmann self-assigned this Jul 31, 2020
@nlohmann
Copy link
Owner

Thanks for reporting! This is indeed a bug. I had code to skip a comment, but did not check for situations with two or more consecutive comments. Replacing an if with a while does the job. I will open a PR.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jul 31, 2020
@nlohmann nlohmann added this to the Release 3.9.1 milestone Jul 31, 2020
@nlohmann
Copy link
Owner

Can you please try with 3888b16?

@mattbement
Copy link
Author

It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants