From 60b72edfba8a0fbe887f86dc26eb572e02b9ec19 Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Wed, 13 Mar 2013 11:26:49 +1300 Subject: [PATCH] FIX Parsing heredoc, nowdoc & comments in ConfigStaticManifest --- core/manifest/ConfigStaticManifest.php | 5 ++- .../manifest/ConfigStaticManifestTest.php | 33 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/core/manifest/ConfigStaticManifest.php b/core/manifest/ConfigStaticManifest.php index 486871e10..339a88e3a 100644 --- a/core/manifest/ConfigStaticManifest.php +++ b/core/manifest/ConfigStaticManifest.php @@ -268,6 +268,9 @@ class SS_ConfigStaticManifest_Parser { else if($type == ';' || $type == ',' || $type == '=') { break; } + else if($type == T_COMMENT) { + // NOP + } else { user_error('Unexpected token when building static manifest: '.print_r($token, true), E_USER_ERROR); } @@ -317,7 +320,7 @@ class SS_ConfigStaticManifest_Parser { $this->statics[$class][$variable] = array( 'access' => $access, - 'value' => eval('return '.$value.';') + 'value' => eval('return '.trim($value).";\n") ); if($token == ',') $this->parseStatic($access, $class); diff --git a/tests/core/manifest/ConfigStaticManifestTest.php b/tests/core/manifest/ConfigStaticManifestTest.php index ceaa13da1..fdd5aab83 100644 --- a/tests/core/manifest/ConfigStaticManifestTest.php +++ b/tests/core/manifest/ConfigStaticManifestTest.php @@ -20,9 +20,20 @@ class ConfigStaticManifestTest extends SapphireTest { static $sfloat = 2.5; static $sstring = 'string'; static $sarray = array(1, 2, array(3, 4), 5); + static $sheredoc = <<parseSelf()->getStatics(); + $this->assertEquals(self::$commented_int, $statics[__CLASS__]['commented_int']['value']); + $this->assertEquals(self::$commented_string, $statics[__CLASS__]['commented_string']['value']); + } + public function testIgnoresMethodStatics() { $statics = $this->parseSelf()->getStatics(); $this->assertNull(@$statics[__CLASS__]['method_static']);