livewire icon indicating copy to clipboard operation
livewire copied to clipboard

Fix localization url in HttpConnectionHandler.php

Open dennisvandalen opened this issue 4 years ago • 5 comments

This pull request fixes wrong order of the arguments supplied the Str::replaceFirst($search, $replace, $subject) helper function in the HttpConnectionHandler. This introduced a bug where when you were not logged in and using locale in the url you were redirected to the login page in the livewire message. This bug is introduced in Livewire v2.3.14

https://laravel.com/docs/8.x/helpers#method-str-replace-first

I started having issues after adding https://github.com/mcamara/laravel-localization to my project.

dennisvandalen avatar Jan 25 '22 15:01 dennisvandalen

@dennisvandalen thanks for the PR!

Do you think there is anyway we can add a test for this, so it doesn't happen again? It may be to complex to test, but would be nice if we could!

joshhanley avatar Jan 25 '22 22:01 joshhanley

@joshhanley I tried to write a test but I'm not familiar enough with the internals to write a decent test. Sorry

dennisvandalen avatar Jan 25 '22 23:01 dennisvandalen

@dennisvandalen no worries! Any chance you can create a small repo for me, that demonstrates the issue, so I can then use it to test out your fix? Hopefully then I should be able to come up with a test for it then.

Thanks!

joshhanley avatar Feb 07 '22 04:02 joshhanley

@joshhanley I've created a demo here: https://github.com/dennisvandalen/livewire-httpconnectionhandler-demo

I actually found 2 cases where Livewire requests break when using this package to do localization. One is when you don't have a root route. And the second is when the root route is behing an authentication middleware.

I hope it helps.

dennisvandalen avatar Feb 10 '22 23:02 dennisvandalen

@joshhanley anything else I can do here? A quick glance at the documentation of Str::replaceFirst should make it clear that the current implementation is a typo and my 1 change should put the parameters in the right order.

static string replaceFirst(string $search, string $replace, string $subject)

Thanks

dennisvandalen avatar Sep 18 '22 07:09 dennisvandalen

@dennisvandalen thanks for providing that repo, I finally got a chance to have a look and it clearly demonstrated the issue. We didn't have the time to work out a test for it, so just merged the fix anyway. Thanks for the PR! 🙂

joshhanley avatar Nov 17 '22 21:11 joshhanley