Skip to content

Wrong controller filter processing because of faulty regular expression generation #1907

Description

@hwiesmann

Describe the bug
Filters::processFilters methods replaces internally filter expressions with wrong regular expressions.

CodeIgniter 4 version
CodeIgniter4 Beta 0.0.1

Affected module(s)
Filters

Expected behaviour, and steps to reproduce if appropriate
Assume the following filter statement in Config/Filters.php:

public $filters = ['login' => ['before' => ['company/*']]];

This filter setting should set a filter for controller Company. Unfortunately, due to the wrong filter processing also controllers like CompanyXYZ will have the filter applied.

The reason for this wrong behaviour is that - for example - 'company/' is replaced by the regular expression 'company.+' which is basically equivalent with 'company'. But this is not correct.

The two statements responsible for the replacement are:

$path = strtolower(str_replace('/*', '*', $path));
$path = trim(str_replace('*', '.+', $path), '/ ');

I do not know why str_replace('/*', '*', $path) is required?! At least in my example this is the root for the problems.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions