diff --git a/system/View/Parser.php b/system/View/Parser.php index 6834c003e500..6f62ca4fb333 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -289,7 +289,7 @@ protected function parsePair(string $variable, array $data, string $template): a */ foreach ($matches as $match) { // Loop over each piece of $data, replacing - // it's contents so that we know what to replace in parse() + // its contents so that we know what to replace in parse() $str = ''; // holds the new contents for this tag pair. foreach ($data as $row) { @@ -338,8 +338,7 @@ protected function parsePair(string $variable, array $data, string $template): a $str .= $out; } - // Escape | character from filters as it's handled as OR in regex - $escapedMatch = preg_replace('/(?assertSame("Super Heroes\nTom Dick Henry ", $this->parser->renderString($template)); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/5825 + */ + public function testParseLoopVariableWithParentheses() + { + $data = [ + 'title' => 'Super Heroes', + 'powers' => [ + ['name' => 'Tom'], + ['name' => 'Dick'], + ['name' => 'Henry'], + ], + ]; + + $template = "{title}\n{powers}({name}) {/powers}"; + + $this->parser->setData($data); + $this->assertSame("Super Heroes\n(Tom) (Dick) (Henry) ", $this->parser->renderString($template)); + } + public function testParseLoopObjectProperties() { $obj1 = new stdClass();