Skip to content

Commit

Permalink
Fix parsing modifiers when encountering literal brackets (#16302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-H authored Jan 19, 2023
1 parent 618f433 commit dfd3113
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 5 deletions.
134 changes: 134 additions & 0 deletions _build/test/Tests/Model/modParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,140 @@ public function providerProcessElementTags() {
'depth' => 0
]
],
[
// Various tests for literal brackets [] in the modifier
[
'processed' => 1,
'content' => "[]"
],
"[[+tag1:notempty=`[]`]]",
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 0
]
],
[
// Test for literal []'s not being broken things
[
'processed' => 1,
'content' => "[ ][ ]"
],
"[[+tag1:notempty=`[ ][ ]`]]",
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 0
]
],
[
[
'processed' => 1,
'content' => "["
],
"[[+tag1:notempty=`[`]]",
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 0
]
],
[
[
'processed' => 1,
'content' => "["
],
"[[!+tag1:notempty=`[`]]",
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 0
]
],
[
[
'processed' => 1,
'content' => "]"
],
"[[+tag1:notempty=`]`]]",
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 0
]
],
[
// various special characters in the modifier
[
'processed' => 1,
'content' => "]=:["
],
"[[+tag1:notempty=`]=:[`]]",
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 0
]
],
[
// tags within brackets
[
'processed' => 1,
'content' => '<input type="text" name="item[ Tag2 ][name]" />'
],
'[[+tag1:notempty=`<input type="text" name="item[ [[+tag2]] ][name]" />`]]',
[
'parentTag' => '',
'processUncacheable' => true,
'removeUnprocessed' => false,
'prefix' => '[[',
'suffix' => ']]',
'tokens' => [],
'depth' => 1
]
],
// tags directly within brackets
// @todo this test fails
// [
// [
// 'processed' => 1,
// 'content' => '<input type="text" name="item[Tag2][name]" />'
// ],
// '[[+tag1:notempty=`<input type="text" name="item[[[+tag2]]][name]" />`]]',
// [
// 'parentTag' => '',
// 'processUncacheable' => true,
// 'removeUnprocessed' => false,
// 'prefix' => '[[',
// 'suffix' => ']]',
// 'tokens' => [],
// 'depth' => 1
// ]
// ],
];
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/Revolution/Filters/modInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ public function filter(&$element)
case '[':
if ($chars[$i + 1] === '[') {
$depth++;
$depth === 0 ? $command .= $char.$char : $commandModifiers .= $char.$char;
$inModifier ? $commandModifiers .= $char.$char : $command .= $char.$char;
$skipNext = true;
}
else {
$depth === 0 ? $command .= $char : $commandModifiers .= $char;
$inModifier ? $commandModifiers .= $char : $command .= $char;
}
break;

// `]]` indicates the end of a nested tag, which decreases the depth.
// The character is added to either the command or the commandModifiers
case ']':
if ($chars[$i + 1] === ']') {
$depth === 0 ? $command .= $char.$char : $commandModifiers .= $char.$char;
$inModifier ? $commandModifiers .= $char.$char : $command .= $char.$char;
$depth--;
$skipNext = true;
}
else {
$depth === 0 ? $command .= $char : $commandModifiers .= $char;
$inModifier ? $commandModifiers .= $char : $command .= $char;
}

break;
Expand All @@ -110,7 +110,7 @@ public function filter(&$element)
$inModifier = !$inModifier;
}
else {
$commandModifiers .= $char;
$inModifier ? $commandModifiers .= $char : $command .= $char;
}
break;
// The `:` sign (colon) is a separator between multiple commands in a string.
Expand Down

0 comments on commit dfd3113

Please sign in to comment.