Permalink
Browse files

FIX Incorrect parsing of T_STRING values in class spec parsing

* Due to missing break, the T_STRING case would fall through to array.
* The values were being added to the wrong variable.
* Added missing support for missing null values.
  • Loading branch information...
1 parent b8a51c3 commit d3e4863f520f492665818a6c200ec6cbd8efd757 @ajshort ajshort committed Mar 22, 2013
Showing with 16 additions and 3 deletions.
  1. +5 −3 core/Object.php
  2. +11 −0 tests/core/ObjectTest.php
View
@@ -194,11 +194,13 @@ public static function parse_class_spec($classSpec) {
case T_STRING:
switch($token[1]) {
- case 'true': $args[] = true; break;
- case 'false': $args[] = false; break;
+ case 'true': $bucket[] = true; break;
+ case 'false': $bucket[] = false; break;
+ case 'null': $bucket[] = null; break;
default: throw new Exception("Bad T_STRING arg '{$token[1]}'");
}
-
+ break;
+
case T_ARRAY:
// Add an empty array to the bucket
$bucket[] = array();
View
@@ -349,6 +349,17 @@ public function testParseClassSpec() {
array('Versioned',array('Stage\'Stage,Live\'Live', 'Live')),
Object::parse_class_spec("Versioned('Stage\'Stage,Live\'Live','Live')")
);
+
+ // True, false and null values
+ $this->assertEquals(
+ array('ClassName', array('string', true, array('string', false))),
+ Object::parse_class_spec('ClassName("string", true, array("string", false))')
+ );
+ $this->assertEquals(
+ array('ClassName', array(true, false, null)),
+ Object::parse_class_spec('ClassName(true, false, null)')
+ );
+
// Array
$this->assertEquals(
array('Enum',array(array('Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted')),

0 comments on commit d3e4863

Please sign in to comment.