diff -ur ./includes/token.inc ../../drupal-7.x-dev/includes/token.inc --- ./includes/token.inc 2010-10-18 03:13:07.000000000 +0200 +++ ../../drupal-7.x-dev/includes/token.inc 2010-12-23 19:05:00.000000000 +0100 @@ -18,7 +18,7 @@ * * Tokens follow the form: [$type:$name], where $type is a general class of * tokens like 'node', 'user', or 'comment' and $name is the name of a given - * placeholder. For example, [node:title]. + * placeholder. For example, [node:title] or [node:created:since]. * * In addition to raw text containing placeholders, modules may pass in an array * of objects to be used when performing the replacement. The objects should be @@ -104,9 +104,16 @@ * An associative array of discovered tokens, grouped by type. */ 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); + // Matches tokens with the following pattern: [$type:$name] + // $type and $name may not contain any [ ] or white space. + // Note: the first ':' is used to get $type. + preg_match_all('/ + \[ # [ - pattern start + ([^\s\[\]:]*) # match $type not containing whitespace : [ or ] + : # : - separator + ([^\s\[\]]*) # match $name not containing whitespace [ or ] + \] # ] - pattern end + /x', $text, $matches); $types = $matches[1]; $tokens = $matches[2]; diff -ur ./modules/system/system.test ../../drupal-7.x-dev/modules/system/system.test --- ./modules/system/system.test 2010-12-01 01:23:36.000000000 +0100 +++ ../../drupal-7.x-dev/modules/system/system.test 2010-12-23 18:09:24.000000000 +0100 @@ -1634,6 +1634,42 @@ } /** + * 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; + + // Set a site variable for Token to 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' => ']'), + ); + + // 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() { Only in ../../drupal-7.x-dev/sites: .DS_Store Only in ../../drupal-7.x-dev/sites/all: .DS_Store Only in ../../drupal-7.x-dev/sites/all/modules: .DS_Store Only in ../../drupal-7.x-dev/sites/all/modules: contrib Only in ../../drupal-7.x-dev/sites/all/modules: drilldown Only in ../../drupal-7.x-dev/sites/all/modules: gr Only in ../../drupal-7.x-dev/sites/all/modules: graphapi Only in ../../drupal-7.x-dev/sites/all/themes: .DS_Store Only in ../../drupal-7.x-dev/sites/default: .DS_Store Only in ../../drupal-7.x-dev/sites/default: CVS Only in ../../drupal-7.x-dev/sites/default: files Only in ../../drupal-7.x-dev/sites/default: settings.php Only in ../../drupal-7.x-dev/sites: dr