Skip to content

Commit

Permalink
catching more invalid syntax conditions,
Browse files Browse the repository at this point in the history
fixing exception inheritance
  • Loading branch information
deceze committed Oct 22, 2012
1 parent 4a3e500 commit bbad773
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Rison/RisonDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ protected function init() {
}

public function decode() {
return $this->parseValue();
$value = $this->parseValue();
if ($this->next() !== false) {
$this->parseError('Invalid syntax');
}
return $value;
}

protected function parseValue() {
Expand Down Expand Up @@ -221,7 +225,7 @@ protected function next() {
do {
if ($this->index >= $this->length) {
$this->eof = true;
return;
return false;
}
$c = $this->rison[$this->index++];
} while (strpos($this->whitespace, $c) !== false);
Expand Down
2 changes: 1 addition & 1 deletion Rison/RisonParseErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RisonParseErrorException extends \RuntimeException {

protected $rison;

public function __construct($rison, $message, $code = 0, Exception $previous = null) {
public function __construct($rison, $message, $code = 0, \Exception $previous = null) {
$this->rison = $rison;
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Usage
Information
-----------

Version: 0.9
Version: 0.91
Author: David Zentgraf
Contact: rison@kunststube.net
License: Public Domain
7 changes: 7 additions & 0 deletions tests/Rison/RisonDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,11 @@ public function testAllTypesNested() {
$this->assertEquals(json_decode($json, true), R\rison_decode($rison));
}

/**
* @expectedException Kunststube\Rison\RisonParseErrorException
*/
public function textTwoLiterals() {
R\rison_decode('foo bar');
}

}

0 comments on commit bbad773

Please sign in to comment.