Skip to content
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

Merge query params instead of just appending them #197

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

riasvdv
Copy link
Owner

@riasvdv riasvdv commented Dec 27, 2024

Fixes #192

@riasvdv riasvdv marked this pull request as ready for review December 27, 2024 11:03
@riasvdv riasvdv merged commit fb16f41 into main Dec 27, 2024
15 checks passed
Copy link

@digilist digilist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! I've taken a look it, but it's not really solving the issue yet. Can you take another look at it?

Besides, I am wondering about the priority of the query paramers if there are query parameters both in the destination URL and the request URL. Which one takes precedence and overrides the other one?

I do not have an opinion or scenario in mind right now, so maybe it can stay like it is. Or maybe it would be good to have it configurable 🤔 Anyway, just wanted to share this thought.

$query = array_merge($destination_query, $request->query());

if (count($query)) {
$destination .= '?' . http_build_query($query);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can still lead to invalid URLs with duplicate question marks when the destination URL already contains a query string. The query string needs to be removed first before appending the merged query string.

In the test below you are setting a query string on the source URL but not on the destination URL, which is a different scenario.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this issue, please see #202

The solution gives precedence to the destination's query parameters, as they have to be stated explicitly when defining a redirect.

I am also thinking about a solution to redirect URLs independently of their query parameters (and if the preserve_query_parameters config is set, to forward all query parameters also to the destination URL). But as this comment suggests, the regex type shall be used for this use case: #12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @faltjo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge query strings from redirect destination and request
3 participants