Skip to content

Bug: esc(..., 'raw') fails on recursive data structures #8624

Description

@Cleric-K

PHP Version

8.2

CodeIgniter4 Version

4.4.6

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

In the process of upgrading from CI3 -> 4, I encountered a problem with a view() that uses a fairly complex $data structure including &references between elements. Even though the view() helper calls setData() with $context = 'raw', this still ends up in infinite recursion because esc() iterates through the fields of the array and calls esc(..., 'raw') on them. This whole operation is completely unnecessary because in the end it does not escape anything. However, because of the self-references, this walking of the array ends up in infinite recursion.

The esc() function should return $data immediately in the case of 'raw'. There's no need to walk the whole array tree just to build it anew.

Steps to Reproduce

A non-realistic example, just to illustrate the point:

$data = ['key' => []];
$data['key']['recur'] = &$data;
esc($data, 'raw');

Expected Output

The exact same $data array, without iterating its values.

Anything else?

No response

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions