Commit d8e62ff2 authored by Dries's avatar Dries

- Patch #681782 by Dave Reid: 'clean' option in token_replace() does not do anything.

parent 4f0e59e1
......@@ -78,6 +78,9 @@ function token_replace($text, array $data = array(), array $options = array()) {
$replacements = array();
foreach (token_scan($text) as $type => $tokens) {
$replacements += token_generate($type, $tokens, $data, $options);
if (!empty($options['clear'])) {
$replacements += array_fill_keys($tokens, '');
}
}
// Optionally alter the list of replacement values.
......
......@@ -1449,26 +1449,30 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
$source .= '[node:author:name]'; // Node author's name
$source .= '[node:created:since]'; // Time since the node was created
$source .= '[current-user:name]'; // Current user's name
$source .= '[user:name]'; // No user passed in, should be untouched
$source .= '[date:short]'; // Short date format of REQUEST_TIME
$source .= '[bogus:token]'; // Nonexistent token, should be untouched
$source .= '[user:name]'; // No user passed in, should be untouched
$source .= '[bogus:token]'; // Non-existent token
$target = check_plain($node->title);
$target .= check_plain($account->name);
$target .= format_interval(REQUEST_TIME - $node->created, 2, $language->language);
$target .= check_plain($user->name);
$target .= '[user:name]';
$target .= format_date(REQUEST_TIME, 'short', '', NULL, $language->language);
$target .= '[bogus:token]';
// Test that the clear parameter cleans out non-existent tokens.
$result = token_replace($source, array('node' => $node), array('language' => $language, 'clear' => TRUE));
$result = $this->assertFalse(strcmp($target, $result), 'Valid tokens replaced while invalid tokens cleared out.');
// Test without using the clear parameter (non-existant token untouched).
$target .= '[user:name]';
$target .= '[bogus:token]';
$result = token_replace($source, array('node' => $node), array('language' => $language));
$this->assertFalse(strcmp($target, $result), 'Valid tokens replaced while invalid tokens ignored.');
// Check that the results of token_generate are sanitized properly. This does NOT
// test the cleanliness of every token -- just that the $sanitize flag is being
// passed properly through the call stack and being handled correctly by a 'known'
// token, [node:title].
$this->assertFalse(strcmp($target, $result), t('Basic placeholder tokens replaced.'));
$raw_tokens = array('title' => '[node:title]');
$generated = token_generate('node', $raw_tokens, array('node' => $node));
$this->assertFalse(strcmp($generated['[node:title]'], check_plain($node->title)), t('Token sanitized.'));
......
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