Skip to content

Commit 09b0bcb

Browse files
authored
Merge pull request #425 from marcandre/fix_pure_parser
Fix pure parser with unclosed arrays / objects [Fix #314]
2 parents 03f1699 + 5b4f1ba commit 09b0bcb

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

lib/json/pure/parser.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ def parse_array
242242
@max_nesting.nonzero? && @current_nesting > @max_nesting
243243
result = @array_class.new
244244
delim = false
245-
until eos?
245+
loop do
246246
case
247+
when eos?
248+
raise ParserError, "unexpected end of string while parsing array"
247249
when !UNPARSED.equal?(value = parse_value)
248250
delim = false
249251
result << value
@@ -274,8 +276,10 @@ def parse_object
274276
@max_nesting.nonzero? && @current_nesting > @max_nesting
275277
result = @object_class.new
276278
delim = false
277-
until eos?
279+
loop do
278280
case
281+
when eos?
282+
raise ParserError, "unexpected end of string while parsing object"
279283
when !UNPARSED.equal?(string = parse_string)
280284
skip(IGNORE)
281285
unless scan(PAIR_DELIMITER)

tests/fixtures/fail29.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{

tests/fixtures/fail30.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[

tests/fixtures/fail31.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1, 2, 3,

tests/fixtures/fail32.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"foo": "bar"

0 commit comments

Comments
 (0)