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

Fix pure parser with unclosed arrays / objects [Fix #314] #425

Merged
merged 1 commit into from Aug 14, 2020
Merged
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
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"