Skip to content

Commit 58734a6

Browse files
authored
Merge pull request #492 from sjahu/pure-comment-regex-fix
Relax Pure::Parser's comment regex to allow any characters in a multi-line comment
2 parents e9dfe1d + 5cff8c1 commit 58734a6

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/json/pure/parser.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ class Parser < StringScanner
3939
//[^\n\r]*[\n\r]| # line comments
4040
/\* # c-style comments
4141
(?:
42-
[^*/]| # normal chars
43-
/[^*]| # slashes that do not start a nested comment
44-
\*[^/]| # asterisks that do not end this comment
45-
/(?=\*/) # single slash before this comment's end
42+
[\s\S]*? # any char, repeated lazily
4643
)*
4744
\*/ # the End of this comment
4845
|[ \t\r\n]+ # whitespaces: space, horizontal tab, lf, cr

test/json/json_parser_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ def test_parse_comments
272272
EOT
273273
assert_raise(ParserError) { parse(json) }
274274
json = <<EOT
275+
{
276+
"key1":"value1" /* multi line
277+
// nested eol comment
278+
/* legal nested multi line comment start sequence */
279+
}
280+
EOT
281+
assert_equal({ "key1" => "value1" }, parse(json))
282+
json = <<EOT
275283
{
276284
"key1":"value1" /* multi line
277285
// nested eol comment

0 commit comments

Comments
 (0)