Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The Token API uses this regex to match and assemble a list of tokens in a string:
// Matches tokens with the following pattern: [$type:$name]
// $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
([^\[\]]*) # match $name not containing [ or ]
\] # ] - pattern end
/x', $text, $matches);
It uses the *
character which will match zero or more characters, meaning it will match empty token types or tokens, which could lead to unexpected results.
Beta phase evaluation
Issue category | Bug because [:some_text] is not a valid token |
---|---|
Issue priority | Normal because there is unlikely to be any code in core that actually hits this bug. |
Prioritized changes | The main goal of this issue is a bugfix, so it is a prioritized change for the beta phase. |
Disruption | Not disruptive for core or contributed modules unless they were somehow relying on matching empty tokens |
Proposed resolution
Use the +
repetition character (1 or more) rather than *
(0 or more).
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Novice | Instructions |
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
token-not-empty-PASS.patch | 2.28 KB | xjm | |
token-not-empty-FAIL.patch | 1.53 KB | xjm | |
Comments
Comment #1
xjmComment #3
jibranThank you seems straight forward so RTBC.
Comment #4
alexpottCommitted 62ba78d and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation for to the issue summary.