Skip to content

Commit

Permalink
Fix reading lists ending with 0 raising an "Unclosed list" error
Browse files Browse the repository at this point in the history
See issue #12
thekid committed Aug 19, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1c8c590 commit 83ae28f
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ JSON for the XP Framework ChangeLog

## ?.?.? / ????-??-??

## 3.0.2 / 2017-08-19

* Fixed issue #12: Error reading lists ending with 0 - @thekid

## 3.0.1 / 2017-06-29

* Fixed issue #11: Sequential output and empty arrays/objects - @thekid
4 changes: 2 additions & 2 deletions src/main/php/text/json/Input.class.php
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ protected function readObject($nesting) {
} else {
throw new FormatException('Unexpected '.\xp::stringOf($delim).', expecting "," or "}"');
}
} while ($token= $this->nextToken());
} while (null !== ($token= $this->nextToken()));
}

throw new FormatException('Unclosed object');
@@ -142,7 +142,7 @@ protected function readArray($nesting) {
} else {
throw new FormatException('Unexpected '.\xp::stringOf($delim).', expecting "," or "]"');
}
} while ($token= $this->nextToken());
} while (null !== ($token= $this->nextToken()));
}

throw new FormatException('Unclosed list');
10 changes: 10 additions & 0 deletions src/test/php/text/json/unittest/JsonInputTest.class.php
Original file line number Diff line number Diff line change
@@ -203,6 +203,11 @@ public function keys_overwrite_each_other() {
$this->assertEquals(['key' => 'v2'], $this->read('{"key": "v1", "key": "v2"}'));
}

#[@test]
public function object_ending_with_zero() {
$this->assertEquals(['key' => 0], $this->read('{"key": 0}'));
}

#[@test, @expect(FormatException::class), @values([
# '{', '{{', '{{}',
# '}', '}}'
@@ -306,6 +311,11 @@ public function read_list_with_nested_list($source) {
$this->assertEquals(['v1', ['v2', 'v3']], $this->read($source));
}

#[@test]
public function list_ending_with_zero() {
$this->assertEquals([1, 0], $this->read('[1, 0]'));
}

#[@test, @expect(FormatException::class), @values([
# '[', '[[', '[[]',
# ']', ']]'

0 comments on commit 83ae28f

Please sign in to comment.