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

Relax Pure::Parser's comment regex to allow any characters in a multi-line comment #492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/json/pure/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ class Parser < StringScanner
//[^\n\r]*[\n\r]| # line comments
/\* # c-style comments
(?:
[^*/]| # normal chars
/[^*]| # slashes that do not start a nested comment
\*[^/]| # asterisks that do not end this comment
/(?=\*/) # single slash before this comment's end
[\s\S]*? # any char, repeated lazily
)*
\*/ # the End of this comment
|[ \t\r\n]+ # whitespaces: space, horizontal tab, lf, cr
Expand Down
8 changes: 8 additions & 0 deletions tests/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ def test_parse_comments
EOT
assert_raise(ParserError) { parse(json) }
json = <<EOT
{
"key1":"value1" /* multi line
// nested eol comment
/* legal nested multi line comment start sequence */
}
EOT
assert_equal({ "key1" => "value1" }, parse(json))
json = <<EOT
{
"key1":"value1" /* multi line
// nested eol comment
Expand Down