diff options
-rw-r--r-- | includes/token.inc | 7 | ||||
-rw-r--r-- | modules/system/system.test | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/includes/token.inc b/includes/token.inc index edc8a962f..0b05c68f4 100644 --- a/includes/token.inc +++ b/includes/token.inc @@ -77,8 +77,13 @@ * Text with tokens replaced. */ function token_replace($text, array $data = array(), array $options = array()) { + $text_tokens = token_scan($text); + if (empty($text_tokens)) { + return $text; + } + $replacements = array(); - foreach (token_scan($text) as $type => $tokens) { + foreach ($text_tokens as $type => $tokens) { $replacements += token_generate($type, $tokens, $data, $options); if (!empty($options['clear'])) { $replacements += array_fill_keys($tokens, ''); diff --git a/modules/system/system.test b/modules/system/system.test index 7f84d1751..ccb237d74 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -1861,6 +1861,9 @@ class TokenReplaceTestCase extends DrupalWebTestCase { $generated = token_generate('node', $raw_tokens, array('node' => $node), array('sanitize' => FALSE)); $this->assertEqual($generated['[node:title]'], $node->title, t('Unsanitized token generated properly.')); + + // Test token replacement when the string contains no tokens. + $this->assertEqual(token_replace('No tokens here.'), 'No tokens here.'); } /** |