Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
229
Merge Requests
229
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
62ba78dc
Commit
62ba78dc
authored
Dec 24, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2396793
by xjm: Token API will match tokens with empty types or tokens, e.g. [:invalid]
parent
54c74fda
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
2 deletions
+8
-2
core/lib/Drupal/Core/Utility/Token.php
core/lib/Drupal/Core/Utility/Token.php
+2
-2
core/modules/system/src/Tests/System/TokenScanTest.php
core/modules/system/src/Tests/System/TokenScanTest.php
+6
-0
No files found.
core/lib/Drupal/Core/Utility/Token.php
View file @
62ba78dc
...
...
@@ -185,9 +185,9 @@ public function scan($text) {
// $type may not contain : or whitespace characters, but $name may.
preg_match_all
(
'/
\[ # [ - pattern start
([^\s\[\]:]
*
) # match $type not containing whitespace : [ or ]
([^\s\[\]:]
+
) # match $type not containing whitespace : [ or ]
: # : - separator
([^\[\]]
*
) # match $name not containing [ or ]
([^\[\]]
+
) # match $name not containing [ or ]
\] # ] - pattern end
/x'
,
$text
,
$matches
);
...
...
core/modules/system/src/Tests/System/TokenScanTest.php
View file @
62ba78dc
...
...
@@ -24,12 +24,18 @@ function testTokenScan() {
// strings.
$text
=
'First a [valid:simple], but dummy token, and a dummy [valid:token with: spaces].'
;
$text
.
=
'Then a [not valid:token].'
;
$text
.
=
'Then an [:empty token type].'
;
$text
.
=
'Then an [empty token:].'
;
$text
.
=
'Then a totally empty token: [:].'
;
$text
.
=
'Last an existing token: [node:author:name].'
;
$token_wannabes
=
\
Drupal
::
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
->
assertFalse
(
isset
(
$token_wannabes
[
'empty token'
]),
'An empty token has not been matched.'
);
$this
->
assertFalse
(
isset
(
$token_wannabes
[
''
][
'empty token type'
]),
'An empty token type has not been matched.'
);
$this
->
assertFalse
(
isset
(
$token_wannabes
[
''
][
''
]),
'An empty token and type has not been matched.'
);
$this
->
assertTrue
(
isset
(
$token_wannabes
[
'node'
]),
'An existing valid token has been matched.'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment