summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-05-16 16:04:42 +0000
committerDries Buytaert <dries@buytaert.net>2009-05-16 16:04:42 +0000
commit47413f64604422556a32b4aa6594a659101413ff (patch)
treec0987e1bcd1e7105d22492bd0a65e5d70f433997
parentf577c125e84bc3a1f30bcc40105788d0547a534a (diff)
downloadbrdo-47413f64604422556a32b4aa6594a659101413ff.tar.gz
brdo-47413f64604422556a32b4aa6594a659101413ff.tar.bz2
- Patch #368116 by chx, c960657: fixed bug in tokenizer for registry.
-rw-r--r--includes/registry.inc6
-rw-r--r--modules/simpletest/tests/registry.test12
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
+}