Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel][Fragment] InlineFragmentRenderer::createSubRequest should use request locale when populating subRequest object #21546

Copy link
Copy link
Closed
@ThijsFeryn

Description

@ThijsFeryn
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version master

Problem

The InlineFragmentRenderer::createSubRequest method does not use the locale of the main request to populate its subrequest object.

How I discovered this

I discovered this when using the ESI renderer in Twig when no Surrogate-Capability headers were set:

{{ render_esi(url('footer')) }}

In that case Symfony HTTP Kernel falls back to the InlineFragmentRenderer. The missing locale was particularly annoying because I'm using the Silex\Provider\TranslationServiceProvider() in my subrequest to translate data. Because of this bug, the translation service provider always falls back to English.

Possible solution

Add to following line of code at the end of The InlineFragmentRenderer::createSubRequest to fix the issue:

$subRequest->setLocale($request->getLocale());

What about the unit tests?

This is the unit test that initially fails, but that passes when the locale is forwarded:

    /**
     * Test if the locale from the main request is properly forwarded to the subrequest
     */
    public function testCreateSubRequestShouldForwardLocale()
    {
        $method = new \ReflectionMethod('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer','createSubRequest');
        $method->setAccessible(true);
        $request = Request::create('/');
        $request->setLocale('fr');
        $subRequest = $method->invoke(
            new InlineFragmentRenderer(
                $this->getKernel(
                    $this->returnValue(
                        new Response('foo')
                    )
                )
            ),'/',$request

        );
        $this->assertEquals($request->getLocale(),$subRequest->getLocale());
    }

A side effect is that other unit tests in InlineFragmentRendererTest.php fail because getKernelExpectingRequest no longer matches the expected null locale.

But these are a couple of isolated test cases that can be fixed by executing $request->setLocale('en'); on the expected request object.

Pull request

I have a pull request ready to go. Please review and let me know if the proposed fix is acceptable and if you agree that this is a bug and not a feature.

Thx
Thijs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.