Commit fc104c95 authored by David_Rothstein's avatar David_Rothstein

Issue #1035292 by Désiré, vijaycs85, wizonesolutions, oriol_e9g, ACF, achton,...

Issue #1035292 by Désiré, vijaycs85, wizonesolutions, oriol_e9g, ACF, achton, darkadept: Fixed Dynamic tokens can't have spaces.
parent 1d378ff8
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.
......
......@@ -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);
......
......@@ -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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment