Framework: Dot / Underscore inputs inconsistent result after symfony/http-foundation 5.2 update

Created on 15 Dec 2020  路  13Comments  路  Source: laravel/framework

  • Laravel Version: 8.18.1
  • PHP Version: 7.4.12

Description:

symfony/http-foundation 5.2 changed their automatic dot to underscore translation in inputs. However, now you can't seem to access the inputs using Laravel.

Both of these tests are using the same Laravel version.

With symfony/http-foundation 5.1.9

false // has('test.here)
null // input('test.here')
true // has('test_here')
"testing" // input('test_here')
array:1 [
  "test_here" => "testing"
]

With symfony/http-foundation 5.2.0

true // has('test.here)
null // input('test.here')
false // has('test_here')
null // input('test_here')
array:1 [
  "test.here" => "testing"
]

There is now no way of accessing this input

Steps To Reproduce:

Example controller code:

class UserController extends Controller
{
    public function index(Request $request)
    {
        dd(
            $request->has('test.here'),
            $request->input('test.here'),
            $request->has('test_here'),
            $request->input('test_here'),
            $request->all(),
        );
    }
}

Unit test to trigger

class ExampleTest extends TestCase
{
    public function testExample()
    {
        $response = $this->get('/route?test.here=testing');
    }
}

bug

All 13 comments

I can confirm that this behavior was changed. I'll pick this up with the Symfony team.

I think this PR is what's causing it: https://github.com/symfony/symfony/pull/37272

I talked to the Symfony team about this and this is actually a bug fix. Before it wasn't possible to retrieve inputs with a dot notation directly. But now it is.

We're also looking into why input('test.here') isn't returning the input. Thanks

We're also looking into why input('test.here') isn't returning the input. Thanks

Is there an issue I can track for that part?

There's no issue for that atm as this has always been the same behavior.

That's what this issue was for though. Since the Symfony change (which I think was a fair bug fix), the framework is unable to read inputs with dots.

I'll re-open this and take a look soon.

Yeah so ->input( uses data_get under the hood for array based keys and JSON nesting. So this doesn't works for keys using dot in their notation. You'll need to use ->get( instead.

See https://laravel.com/docs/8.x/requests#retrieving-an-input-value

Screenshot 2020-12-15 at 17 55 35

Screenshot 2020-12-15 at 17 55 31

@driesvints Apologies for the delay, but I think there is still an issue.

When running via unit tests (like my example above), it stays as a dot.
When running via a web server (or artisan serve), it gets converted to the underscore.

In both instances, I'm just doing looking at $request->all().

@giggsey you're probably running different PHP versions for those or have different dependencies installed. Please try a support channel.

Same PHP version, same code base.

I'll keep digging later today/tomorrow, but my current findings are that PHP converts dots to underscores in _GET. Running via unit tests calls http-foundations Request::create, which calls HeaderUtils::parseQuery from https://github.com/symfony/symfony/pull/37272.

When running via the web, Request::createFromGlobals() is used instead (_GET), and HeaderUtils::parseQuery is never called.

Confirmed that Symfony does the same, so I've reported it their side.

Thanks for the help @driesvints

Thanks @nicolas-grekas!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzp819739483 picture lzp819739483  路  3Comments

progmars picture progmars  路  3Comments

felixsanz picture felixsanz  路  3Comments

iivanov2 picture iivanov2  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments