Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
d8e62ff2
Commit
d8e62ff2
authored
Mar 12, 2010
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#681782
by Dave Reid: 'clean' option in token_replace() does not do anything.
parent
4f0e59e1
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/token.inc
+3
-0
3 additions, 0 deletions
includes/token.inc
modules/system/system.test
+10
-6
10 additions, 6 deletions
modules/system/system.test
with
13 additions
and
6 deletions
includes/token.inc
+
3
−
0
View file @
d8e62ff2
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
modules/system/system.test
+
10
−
6
View file @
d8e62ff2
...
...
@@ -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.'
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment