Skip to content

Commit

Permalink
Merge pull request #425 from marcandre/fix_pure_parser
Browse files Browse the repository at this point in the history
Fix pure parser with unclosed arrays / objects [Fix #314]
  • Loading branch information
hsbt committed Aug 14, 2020
2 parents 03f1699 + 5b4f1ba commit 09b0bcb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/json/pure/parser.rb
Expand Up @@ -242,8 +242,10 @@ def parse_array
@max_nesting.nonzero? && @current_nesting > @max_nesting
result = @array_class.new
delim = false
until eos?
loop do
case
when eos?
raise ParserError, "unexpected end of string while parsing array"
when !UNPARSED.equal?(value = parse_value)
delim = false
result << value
Expand Down Expand Up @@ -274,8 +276,10 @@ def parse_object
@max_nesting.nonzero? && @current_nesting > @max_nesting
result = @object_class.new
delim = false
until eos?
loop do
case
when eos?
raise ParserError, "unexpected end of string while parsing object"
when !UNPARSED.equal?(string = parse_string)
skip(IGNORE)
unless scan(PAIR_DELIMITER)
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/fail29.json
@@ -0,0 +1 @@
{
1 change: 1 addition & 0 deletions tests/fixtures/fail30.json
@@ -0,0 +1 @@
[
1 change: 1 addition & 0 deletions tests/fixtures/fail31.json
@@ -0,0 +1 @@
[1, 2, 3,
1 change: 1 addition & 0 deletions tests/fixtures/fail32.json
@@ -0,0 +1 @@
{"foo": "bar"

0 comments on commit 09b0bcb

Please sign in to comment.