diff options
author | David Rothstein <drothstein@gmail.com> | 2013-03-30 14:48:22 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2013-03-30 14:48:22 -0400 |
commit | fc104c95bde2db0c6e266e76205a870be0e221c3 (patch) | |
tree | 5dfc5473f817a33a02021e111b77510015d7dd64 | |
parent | 1d378ff882353b32716837d3ff901305e0aa05a8 (diff) | |
download | brdo-fc104c95bde2db0c6e266e76205a870be0e221c3.tar.gz brdo-fc104c95bde2db0c6e266e76205a870be0e221c3.tar.bz2 |
Issue #1035292 by Désiré, vijaycs85, wizonesolutions, oriol_e9g, ACF, achton, darkadept: Fixed Dynamic tokens can't have spaces.
-rw-r--r-- | CHANGELOG.txt | 1 | ||||
-rw-r--r-- | includes/token.inc | 6 | ||||
-rw-r--r-- | modules/system/system.test | 31 |
3 files changed, 35 insertions, 3 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0f017bf6f..2ec918edf 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,7 @@ Drupal 7.22, xxxx-xx-xx (development version) ----------------------- +- Fixed Drupal's token-replacement system to allow spaces in the token value. - Changed the default behavior after a user creates a node they do not have access to view. The user will now be redirected to the front page rather than an access denied page. diff --git a/includes/token.inc b/includes/token.inc index 402aeae01..5e9ece85d 100644 --- a/includes/token.inc +++ b/includes/token.inc @@ -113,13 +113,13 @@ function token_replace($text, array $data = array(), array $options = array()) { */ function token_scan($text) { // Matches tokens with the following pattern: [$type:$name] - // $type and $name may not contain [ ] or whitespace characters. - // $type may not contain : characters, but $name may. + // $type and $name may not contain [ ] characters. + // $type may not contain : or whitespace characters, but $name may. preg_match_all('/ \[ # [ - pattern start ([^\s\[\]:]*) # match $type not containing whitespace : [ or ] : # : - separator - ([^\s\[\]]*) # match $name not containing whitespace [ or ] + ([^\[\]]*) # match $name not containing [ or ] \] # ] - pattern end /x', $text, $matches); diff --git a/modules/system/system.test b/modules/system/system.test index abd21aae6..84ed269bc 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -2681,3 +2681,34 @@ class SystemIndexPhpTest extends DrupalWebTestCase { } } +/** + * Test token replacement in strings. + */ +class TokenScanTest extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Token scanning', + 'description' => 'Scan token-like patterns in a dummy text to check token scanning.', + 'group' => 'System', + ); + } + + /** + * Scans dummy text, then tests the output. + */ + function testTokenScan() { + // Define text with valid and not valid, fake and existing token-like + // strings. + $text = 'First a [valid:simple], but dummy token, and a dummy [valid:token with: spaces].'; + $text .= 'Then a [not valid:token].'; + $text .= 'Last an existing token: [node:author:name].'; + $token_wannabes = token_scan($text); + + $this->assertTrue(isset($token_wannabes['valid']['simple']), 'A simple valid token has been matched.'); + $this->assertTrue(isset($token_wannabes['valid']['token with: spaces']), 'A valid token with space characters in the token name has been matched.'); + $this->assertFalse(isset($token_wannabes['not valid']), 'An invalid token with spaces in the token type has not been matched.'); + $this->assertTrue(isset($token_wannabes['node']), 'An existing valid token has been matched.'); + } +} + |