Skip to content

Bug: with the parser, nl2br in a foreach duplicates entries. #2360

Description

@SteeveDroz

Describe the bug
When using the parser, if a loop is made with {elements}{/elements}, the entries are doubled if a nl2br is used on an attribute of elements.

CodeIgniter 4 version
4.0.0-rc.3

Affected module(s)
Parser

Expected behavior, and steps to reproduce if appropriate
Given the following code in controller:

public function bug()
{
    $elements = [
        ['a' => 'foo'.PHP_EOL.'bar'],
        ['a' => 'baz'],
    ];
    return service('parser')
        ->setData([
            'elements' => $elements
        ])
        ->renderString('{elements}<p>{a|nl2br}</p>{/elements}');
}

The result (with added newlines for readability) is:

<p>foo<br />bar</p>
<p>baz</p>
|
<p>foo<br />bar</p>
<p>baz</p>

Description:

  • The nl2br works
  • The | from {a|nl2br} is displayed
  • The loop is called a second time after the |

Context

  • OS: Fedora 30
  • Web server Apache 2.4.41
  • PHP version 7.3.10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions