You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which operating systems have you tested for this bug?
macOS
Which server did you use?
apache
Database
MySQL 8.3.0
What happened?
Using the same key name in an array although on different levels, leads to a premature substitution of {key}, when that {key} is referring in a nested one on a loop substitution.
(Based on the Steps to Reproduce section)
With the current Parser behaviour, both {id} vars will be replaced with their respective value but given that the second {id} is inside {blog_entries}, by 'blindly' replacing all instances of {variable}, {blog_entries}{id}{/blog_entries} will turn into {blog_entries}1{/blog_entries} which will fail to replace the {blog_entries}{id}{/blog_entries} with the proper data when it reaches to the blog_entries array.
ID: id_1
title: My Blog Title Blog
Entries:
id_1 - Title 1 - Body 1
id_1 - Title 2 - Body 2
id_1 - Title 3 - Body 3
id_1 - Title 4 - Body 4
id_1 - Title 5 - Body 5
ID: id_1
title: My Blog Title
Blog Entries:
{items} id_1 - {title} - {body} {/items}
And it fails to properly replace the rest of the data.
Expected Output
ID: id_1
title: My Blog Title
Blog Entries:
sub_id_1 - Title 1 - Body 1
sub_id_2 - Title 2 - Body 2
sub_id_3 - Title 3 - Body 3
sub_id_4 - Title 4 - Body 4
sub_id_5 - Title 5 - Body 5
Anything else?
This behaviour seems to stem from how the Parser::parse() function acts. From my understanding, when the parsing occurs the method loops over the data passed to it and if the data to be replaced isn't an array (Pair) then, it immediately replaces the content (Single). Which means, if there is multiple keys with the same identifier down the line, they will get replaced all at once, breaking further processing specially when using Pairs like {blog_entries}{items}{id}{items}{/blog_entries}.
I propose a solution in which the return of parsePair and parseSingle are stored independently, then merged together (Pairs with Single), and finally the replacement loop happens. With this approach, the replacement happens from the Pairs to Single and the output is as expected since {blog_entries}{items}{id}{items}{/blog_entries} will be {blog_entries}{items}sub_id_1{items}{/blog_entries} before the top {id} replace is triggered.
The text was updated successfully, but these errors were encountered:
CosDiabos
added
the
bug
Verified issues on the current code behavior or pull requests that will fix them
label
Oct 30, 2024
PHP Version
8.3
CodeIgniter4 Version
4.5.5
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
macOS
Which server did you use?
apache
Database
MySQL 8.3.0
What happened?
Using the same key name in an array although on different levels, leads to a premature substitution of
{key}
, when that{key}
is referring in a nested one on a loop substitution.(Based on the Steps to Reproduce section)
With the current Parser behaviour, both
{id}
vars will be replaced with their respective value but given that the second{id}
is inside{blog_entries}
, by 'blindly' replacing all instances of{variable}
,{blog_entries}{id}{/blog_entries}
will turn into{blog_entries}1{/blog_entries}
which will fail to replace the{blog_entries}{id}{/blog_entries}
with the proper data when it reaches to the blog_entries array.Steps to Reproduce
Returns:
Going a level down
Returns:
And it fails to properly replace the rest of the data.
Expected Output
Anything else?
This behaviour seems to stem from how the
Parser::parse()
function acts. From my understanding, when the parsing occurs the method loops over the data passed to it and if the data to be replaced isn't an array (Pair) then, it immediately replaces the content (Single). Which means, if there is multiple keys with the same identifier down the line, they will get replaced all at once, breaking further processing specially when using Pairs like{blog_entries}{items}{id}{items}{/blog_entries}
.I propose a solution in which the return of
parsePair
andparseSingle
are stored independently, then merged together (Pairs with Single), and finally the replacement loop happens. With this approach, the replacement happens from the Pairs to Single and the output is as expected since{blog_entries}{items}{id}{items}{/blog_entries}
will be{blog_entries}{items}sub_id_1{items}{/blog_entries}
before the top{id}
replace is triggered.The text was updated successfully, but these errors were encountered: