-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
[1.x] Fix encoded URL #663
base: 1.x
Are you sure you want to change the base?
Conversation
Please merge this, so I can avoid having to read hieroglyphs in my URL 🙏 |
Also facing this bug, becomes very annoying when dealing with dashboards where the URL has a lot of state. Please merge @reinink especially if 2.0 is dropping soon? Would save a lot of headache |
@RobertBoes Hey just to be clear, is the issue here simply that the query params are harder to read because they are encoded? Or is something broken? Just want to make sure I understand the issue. |
@reinink I'd say it's broken, not just hard to read. Sure, it doesn't have an impact on the server interpreting the URL, but it still leads to strange behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so I did some testing with this, and I don't think it's quite right yet. I think this encoding is actually important otherwise special characters can mess up your query params. For example, in my app I have a search feature. Before this change, searching for "jonathan&amy" works great and results in this URL:
Here I have a single query param — However, after this change I get this URL instead:
Which, as you know, means I now have two query params — This is broken as a result of this change, as putting a special character anywhere in your app that ends up in a query param (which is super common) will break someone's app. So I understand that with the current behavior visiting |
Hey @reinink Maybe I am not following exactly what you mean, but if I understand correctly...
This is expected behavior with the
Surely this is only the
Would result in: ['search' => 'jonathan$amy'] To me it sounds like your app relies on the encoding issues introduced in #592, which this PR tries to fix. If you're worried about breaking existing apps by merging this, I can understand that. However I also think it's a bad idea to call the "bug" a feature, if people do not want encoded URLs. Maybe provide a way to disable it, but leave it on by default? |
Chiming in another idea; Let the user provide the URL. So a default implementation that can be overwritten. For example, I don't care about the path prefix, so then I could easily just get the path+query as was done previously. That way I'd send the same URL to the frontend as what's visible in the browser |
I'd even be happy with an option within the Inertia config to specify what characters should be encoded, e.g. Then you've got more control and everyone wins |
I'd really like to avoid having to create a config option for something...it feels like something that should be solvable without one. @RobertBoes @heychazza what's your primary concern here? The fact that history state gets updated with the encoded query params? Or that they are encoded and now visually look worse? |
I still think this is the best solution! Currently it's quite cumbersome to overwrite the URL generation part. See #503 |
I totally get that, I wouldn't want that to be "yet another config option", or something like
|
Yeah agreed, I'm also using the Spatie Query Builder and it's very hard to understand the URL filters when it's all %20 everything. Would definitely love if we could just bind our own thing, as I do understand its very niche. |
I'm also waiting for merge. temporary solution <?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Inertia\Support\Header;
use Symfony\Component\HttpFoundation\Response;
class FixUrlEncodeInertiaPageRequest
{
/**
* @see https://github.com/inertiajs/inertia-laravel/pull/663
*
* Handle an incoming request.
*
* @param Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response|\Illuminate\Http\JsonResponse) $next
*/
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
if ($request->header(Header::INERTIA)) {
$response->original['url'] = rawurldecode($response->original['url']);
$response->setData($response->original);
}
return $response;
}
} add in service provider register method use App\Infrastructure\Illuminate\ResponseFactory as ServicesResponseFactory;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
use Illuminate\Contracts\View\Factory as ViewFactoryContract;
//register
$this->app->singleton(ResponseFactoryContract::class, function ($app) {
return new ServicesResponseFactory($app[ViewFactoryContract::class], $app['redirect']);
}); <?php
namespace App\Infrastructure\Illuminate;
use Illuminate\Routing\ResponseFactory as RoutingResponseFactory;
final class ResponseFactory extends RoutingResponseFactory
{
public function view($view, $data = [], $status = 200, array $headers = [])
{
if (isset($data['page']['url'])) {
$data['page']['url'] = rawurldecode($data['page']['url']);
}
return parent::view($view, $data, $status, $headers);
}
} |
In #592 URL generation was fixed regarding sub paths. However it did introduce encoding issues; #592 (comment)
With this PR it simply decodes the URL to an unencoded variant, which would then be used on the client to set the current location.