Modifiers on early-parsed variables use the wrong value when one variable name is a prefix of another (embed:body vs embed:body2)
I maintainer di solito rispondono entro 5 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
Direzione di ricerca
Inizia in system/ee/ExpressionEngine/Service/Template/Variables/LegacyParser.php, in parseModifiedVariables(), e segui il modo in cui parseVariableProperties() analizza i risultati di extractVariables(). Riproduci l’esempio body/body2 dell’issue, poi verifica che i modificatori usino il valore del nome del campo corrispondente. Il lavoro è terminato quando entrambi gli ordini dei parametri producono le lunghezze previste per body e body2; l’issue non indica alcun file di test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description of the problem
When two early-parsed variables share a name prefix, such as embed parameters body and body2, a modifier on the longer one can output the shorter one's value. This happens with every modifier, core and add-on, with or without parameters.
It affects every early-parsed variable that goes through LegacyParser::parseModifiedVariables(): embed and layout variables, segment variables ({segment_1} vs {segment_10}), template route variables and global variables. The wrong value comes out with no error, and whether it happens depends on the order of the variables, so it's easy to miss.
How To Reproduce
- Create a template
test/.inner:
body: {embed:body:length}
body2: {embed:body2:length}
- Embed it from
test/outer:
{embed="test/.inner" body="abc" body2="abcdefgh"}
Expected:
body: 3
body2: 8
Actual:
body: 3
body2: 3
- Swap the order of the embed parameters:
{embed="test/.inner" body2="abcdefgh" body="abc"}. The output is now correct:
body: 3
body2: 8
It's the same with parameterised core modifiers ({embed:body2:limit characters="3"} outputs body's value) and with modifiers registered by add-ons.
Error Messages
None. The wrong value is output with no error.
Screenshots / Videos / Template Code
The template code is above.
Environment Details:
- Version: tested on 7.5.28.
parseModifiedVariables()is unchanged in 7.6.0 and on7.dev. - PHP Version: 8.3.30 (FPM)
- OS: Linux
- Web Server: nginx
Possible Solution
In system/ee/ExpressionEngine/Service/Template/Variables/LegacyParser.php, parseModifiedVariables() loops over each early variable $name and calls extractVariables($str, $name). That matches with /{(embed:body.*?)}/, which also catches {embed:body2:length}. The loop then applies the modifiers to embed:body's value and replaces {embed:body2:length} with the result. Nothing checks that the parsed field name is the variable being processed. If embed:body2 happens to be processed first, its tag is already gone by the time embed:body is processed, which is why the order matters.
A check after parseVariableProperties() fixes it:
foreach ($extracted_vars['var_single'] as $modified_var) {
$content = $value;
$var_props = $this->parseVariableProperties($modified_var, $prefix);
// {embed:body2:...} also matches when processing embed:body; skip it so body2 is handled with its own value
if ($var_props['field_name'] !== substr($name, strlen($prefix))) {
continue;
}
...
Additional context
- This is the same kind of bug as #55 (
get_pair_field()matching pair fields with the same prefix). - #3543 (
{path}output affected by{current_path:url_encode}) may be related. It couldn't be reproduced on a clean install at the time. - Found while testing modifiers from the third-party add-on https://github.com/ignetic/ee-extra-modifiers, then confirmed with core
:lengthand:limit.
- Lingua principale
- PHP
- Stelle
- 505
- Fork
- 135
- Merge medio
- 4g 21h
- PR unite (30g)
- 23
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ExpressionEngine/ExpressionEngine
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
ExpressionEngine/ExpressionEngine#5453 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ExpressionEngine/ExpressionEngine#5381 ·
I maintainer di solito rispondono entro 5 giorni
-
Bug: Accepted
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
ExpressionEngine/ExpressionEngine#5117 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
ExpressionEngine/ExpressionEngine#5066 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
EE6
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
ExpressionEngine/ExpressionEngine#4406 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
Tutte le issue di ExpressionEngine/ExpressionEngine
Issue simili
-
"Attempt to read property 'username' on null" error after a user is deletedForse già presa @dicksonlaw583 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
omeka/plugin-SimplePages#49 ·
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
quantum-php/project#222 ·
-
support
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
15.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100