Skip to content

RequestMatcher issue when _controller is a closure #40807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2021
Merged

RequestMatcher issue when _controller is a closure #40807

merged 1 commit into from
Apr 15, 2021

Conversation

Plopix
Copy link
Contributor

@Plopix Plopix commented Apr 13, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

Description

If the matches method of RequestMatcher is used on an attribute which is a closure it crashes.

How did we get it

On a project that is using FOS HTTP Cache, we have this configuration

fos_http_cache:
    cache_control:
        rules:
     -
                match:
                    attributes: { _controller: ^App\\Controller\\.*::.* }
                headers:
                    overwrite: true
                    cache_control: { public: true, private: false, must_revalidate: true, s_maxage: 3600 }

Everything works fine unless you are reaching a controller that is a closure.
You get a
TypeError: preg_match(): Argument #2 ($subject) must be of type string, Closure given which is to me logical.

Proposed solution

Just testing the type of attribute value and return false before crashing preg_match

This PR adds a quick unit test to enforce this.

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Apr 13, 2021
@nicolas-grekas nicolas-grekas changed the base branch from 5.x to 4.4 April 13, 2021 20:03
@Plopix Plopix changed the title RequestMatcher issue when _controller is a closure [HttpFoundation] RequestMatcher issue when _controller is a closure Apr 13, 2021
@carsonbot
Copy link

Hey!

I think @a-menshchikov has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [HttpFoundation] RequestMatcher issue when _controller is a closure RequestMatcher issue when _controller is a closure Apr 14, 2021
@Nyholm
Copy link
Member

Nyholm commented Apr 15, 2021

Lovely, thank you!

@Nyholm Nyholm merged commit d5e8d6e into symfony:4.4 Apr 15, 2021
This was referenced May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants