bref icon indicating copy to clipboard operation
bref copied to clipboard

Value of $_SERVER['QUERY_STRING] different when deployed

Open DaMitchell opened this issue 5 years ago • 2 comments

Description When making a request to /orders?billingAddress.surname=test and accessing the value of $_SERVER['QUERY_STRING'] the expected value should be:

billingAddress.surname=test

Instead the value is:

billingAddress_surname=test

When testing the issue locally using the bref/fpm-dev-gateway and bref/php-74-fpm-dev images and dumping out the values from $_SERVER the expected value can be seen.

Cause When an instance of HttpRequestEvent is created the method HttpRequestEvent::rebuildQueryString is called which passed the value through parse_str causing the conversion. This value is set on the request passed the the FPM process by:

$request->setCustomVar('QUERY_STRING', $event->getQueryString());

Which is here https://github.com/brefphp/bref/blob/master/src/Event/Http/FpmHandler.php#L182. I can also see it being used in the Psr7Bridge here https://github.com/brefphp/bref/blob/master/src/Event/Http/Psr7Bridge.php#L33

DaMitchell avatar Sep 21 '20 15:09 DaMitchell

@mnapoli Any ideas on when this can be addressed? I am happy to put a PR in myself just a little unsure about what you would expect in it. Other than updating the HttpRequestEvent::getQueryString() is there anything else you would expect to be updated?

DaMitchell avatar Sep 29 '20 07:09 DaMitchell

A first step that could be very useful would be to add a failing test case. You can start by looking at these tests: https://github.com/brefphp/bref/blob/master/tests/Event/Http/CommonHttpTest.php#L76-L126 and maybe try to write a new one?

If that doesn't reproduce, then maybe you'll want to add it here: https://github.com/brefphp/bref/blob/master/tests/Handler/FpmHandlerTest.php

If you see a solution feel free to implement it too.

mnapoli avatar Sep 29 '20 10:09 mnapoli

I am migrating a large Api-platform 2.7(SF 6.2, PHP 8.1) to Bref & Serverless, and I am blocked on this problem with (.) becoming (_). Our project has a lot of nested filters in the request query string, and they are not working anymore. I suppose anyone migrating Api-platform would face this issue.

vasoft avatar Feb 12 '23 09:02 vasoft

FYI this PR might be very close to be merged: https://github.com/brefphp/bref/pull/1383

mnapoli avatar Feb 12 '23 09:02 mnapoli

Heya! is there any movement on this issue? Experiencing exactly same issue (param names including dot have underscore in them once Bref stack is deployed).

ApiPlatform makes use of dots pretty standart and having them converted makes it rather difficult to deal with.

@mnapoli any work left / blocker on the PR mentioned? :)

sladg avatar Mar 02 '23 11:03 sladg

@sladg yes, the blocker is this: https://github.com/brefphp/bref/pull/1383#issuecomment-1410054226

Feel free to open a new PR with these changes!

mnapoli avatar Mar 03 '23 10:03 mnapoli

@sladg, to move things forward with the project, we did an unorthodox thing until this PR gets merged. we searched for all the nested filters in the project,(order query string is not an issue), and replaced them back with (.) in the Kernel handle.

` class Kernel extends BrefKernel { use MicroKernelTrait;

public function handle($request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = true): Response
{
    // to be removed once this issue is merged https://github.com/brefphp/bref/issues/756
    $find = [
        'town_name',
        'product_price',
        //...
    ];
    $replace = [
        'town.name',
        'product.price',
        //...
    ];

    $rawRequestServerQueryString  = $request->server->get('QUERY_STRING');
    // fix in the query string
    $newRequestServerQueryString  = str_replace($find, $replace, $request->server->get('QUERY_STRING'));
    // replace the query string only for not to affect the route path
    $newRequestServerRequestUri  = str_replace(
        $rawRequestServerQueryString,
        $newRequestServerQueryString,
        $request->server->get('REQUEST_URI')
    );

    $request->server->set('QUERY_STRING',   $newRequestServerQueryString);
    $request->server->set('REQUEST_URI',    $newRequestServerRequestUri);

    return parent::handle($request, $type, $catch);
}

} `

vasoft avatar Mar 03 '23 11:03 vasoft