diff options
-rw-r--r-- | includes/registry.inc | 6 | ||||
-rw-r--r-- | modules/simpletest/tests/registry.test | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/includes/registry.inc b/includes/registry.inc index 569945746..cfc7ae118 100644 --- a/includes/registry.inc +++ b/includes/registry.inc @@ -262,6 +262,12 @@ function _registry_skip_body(&$tokens) { elseif ($token == '}') { --$num_braces; } + // Consume strings manually as workaround for a bug in PHP < 5.2.3 (see + // http://drupal.org/node/368116). + elseif ($token == '"' || $token == '`' || (is_array($token) && $token[0] == T_START_HEREDOC)) { + $stop = is_array($token) ? T_END_HEREDOC : $token; + while (($token = next($tokens)) && (is_array($token) ? $token[0] : $token) != $stop); + } } } diff --git a/modules/simpletest/tests/registry.test b/modules/simpletest/tests/registry.test index 97ac23da8..9a363849f 100644 --- a/modules/simpletest/tests/registry.test +++ b/modules/simpletest/tests/registry.test @@ -146,12 +146,20 @@ class RegistrySkipBodyTestCase extends DrupalWebTestCase { function testRegistrySkipBody () { // This string contains all three kinds of opening braces. - $function = '<?php function foo () { $x = "{$y}"; $x = "${y}" }'; + $function = '<?php function foo () { $x = "{$y}"; $x = "${y}"; }'; $tokens = token_get_all($function); _registry_skip_body($tokens); // Consume the last } each($tokens); $this->assertIdentical(each($tokens), FALSE, t('Tokens skipped')); + + // Check workaround for PHP < 5.2.3 regarding tokenization of strings + // containing variables. The { contained in the string should not be + // treated as a separate token. + $function = '<?php function foo() { $x = "$y {"; $x = `$y {`; $x = ' . "<<<EOD\n\$y {\nEOD\n; } function bar() {}"; + $tokens = token_get_all($function); + _registry_skip_body($tokens); + $this->assertTrue(each($tokens), t('Tokens not skipped to end of file.')); } -}
\ No newline at end of file +} |