? core.kpf ? sites/default/files ? sites/default/settings.php Index: includes/token.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/token.inc,v retrieving revision 1.9 diff -u -p -r1.9 token.inc --- includes/token.inc 12 Mar 2010 14:33:02 -0000 1.9 +++ includes/token.inc 29 Sep 2010 22:03:47 -0000 @@ -106,7 +106,7 @@ function token_replace($text, array $dat function token_scan($text) { // Matches tokens with the following pattern: [$type:$token] // $type and $token may not contain white spaces. - preg_match_all('/\[([^\s\]:]*):([^\s\]]*)\]/', $text, $matches); + preg_match_all('/\[([^\s\[\]:]*):([^\s\[\]]*)\]/', $text, $matches); $types = $matches[1]; $tokens = $matches[2]; Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.143 diff -u -p -r1.143 system.test --- modules/system/system.test 24 Sep 2010 00:37:44 -0000 1.143 +++ modules/system/system.test 29 Sep 2010 22:03:51 -0000 @@ -1568,6 +1568,47 @@ class TokenReplaceTestCase extends Drupa } /** + * Test to see if tokens are recognized when contained in a string. + * + * We check if valid tokens are recognized as part of a text environment. + * We add various strings as prefix and suffix and assert if the token is + * replaced correctly. + */ + function testSystemTokenRecognition() { + global $language; + $url_options = array( + 'absolute' => TRUE, + 'language' => $language, + ); + + // Set a site variables for the token work with. + variable_set('site_name', 'Drupal'); + + // Generate token prefixes and suffixes. + $tests = array( + array('prefix' => 'this is the ', 'suffix' => ' site'), + array('prefix' => 'this is the', 'suffix' => 'site'), + array('prefix' => '[', 'suffix' => ']'), + array('prefix' => '', 'suffix' => ']]]'), + array('prefix' => '[[[', 'suffix' => ''), + array('prefix' => ':[:', 'suffix' => '--]'), + array('prefix' => '-[-', 'suffix' => ':]:'), + array('prefix' => '[:', 'suffix' => ']'), + array('prefix' => '[site:', 'suffix' => ':name]'), + array('prefix' => '[site:', 'suffix' => ']'), + ); + + // Run the test + // Prefixes and suffixes are added to both the token and the expected return value. + foreach ($tests as $test) { + $input = $test['prefix'] . '[site:name]' . $test['suffix']; + $expected = $test['prefix'] . 'Drupal' . $test['suffix']; + $output = token_replace($input, array(), array('language' => $language)); + $this->assertTrue($output == $expected, t('Token recognized in string %string', array('%string' => $input))); + } + } + + /** * Tests the generation of all system date tokens. */ function testSystemDateTokenReplacement() {