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

Redirect Loop with multiple spaces in the url #6492

Closed
rolandfarkasCOM opened this issue Jul 28, 2021 · 10 comments · Fixed by #6494
Closed

Redirect Loop with multiple spaces in the url #6492

rolandfarkasCOM opened this issue Jul 28, 2021 · 10 comments · Fixed by #6494
Assignees
Labels
Bug Something isn't working Routing Handling URLs
Milestone

Comments

@rolandfarkasCOM
Copy link

rolandfarkasCOM commented Jul 28, 2021

Bug Description

A redirect loop is caused when more than one spaces are in the url.

Expected Behaviour

Page to work normally

Steps to Reproduce

defeated-leopard.jurassic.ninja/?test=test+this+out+as+it+breaks+your+site

I have uninstalled Jetpack, installed AMP, enabled standard mode, selected a static homepage, and changed the permalink settings to Post Name.

So by the looks of it, a combination of the above settings is the cause.

Screenshots

N/A

Additional context

  • WordPress version: Latest
  • Plugin version: Latest
  • Gutenberg plugin version (if applicable):
  • AMP plugin template mode: Standard
  • PHP version: 7.4,8.0
  • OS: UBUNTU
  • Browser: All
  • Device: All

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

@rolandfarkasCOM rolandfarkasCOM added the Bug Something isn't working label Jul 28, 2021
@milindmore22
Copy link
Collaborator

I am able to reproduce this issue with Static Homepage and post name permalink structure.

@westonruter
Copy link
Member

I can reproduce the issue as well, but only when a static front page is selected. It also happens only when the AMP plugin is active alone.

@westonruter
Copy link
Member

I've traced the issue down to a behavior where remove_query_arg() is normalizing URLs to use + for spaces instead of %20:

wp> remove_query_arg('amp', '/?test=one+two+three')
=> string(20) "/?test=one+two+three"
wp> remove_query_arg('amp', '/?test=one%20two%20three')
=> string(20) "/?test=one+two+three"

In contrast, redirect_canonical() is normalizing query strings to use %20 instead of + for spaces, by means of parse_str() plus rawurlencode_deep():

parse_str('test=one+two+three', $parsed_query); echo rawurlencode_deep($parsed_query['test']);
>> one%20two%20three
parse_str('test=one%20two%20three', $parsed_query); echo rawurlencode_deep($parsed_query['test']);
>> one%20two%20three

In this way, \AmpProject\AmpWP\PairedRouting::redirect_extraneous_paired_endpoint() is causing a redirect with query parameters including + but then redirect_canonical() is redirecting to use %20.

@westonruter
Copy link
Member

I've created the fix in #6494.

@westonruter westonruter added the Routing Handling URLs label Jul 28, 2021
@westonruter westonruter self-assigned this Jul 28, 2021
@rolandfarkasCOM
Copy link
Author

Thanks @westonruter & @milindmore22 hopefully an update will be available soon.

@westonruter
Copy link
Member

To be closed when the PR is merged.

We'll give you a prerelease build to use while waiting for 2.1.4.

@westonruter westonruter reopened this Jul 29, 2021
@rolandfarkasCOM
Copy link
Author

Thank you 👍🙏

@westonruter
Copy link
Member

westonruter commented Jul 30, 2021

@rolandfarkasCOM Please use the 2.1.x production build linked from the Development Builds wiki page.

@westonruter
Copy link
Member

QA Passed

After having set the template mode to Standard, setting the homepage to a static page, and setting the permalink structure to post name:

Before, going to: https://wordpress-stable.lndo.site/?test=test+this+out+as+it+breaks+your+site

image

After, no infinite redirect:

image

@rolandfarkasCOM
Copy link
Author

Thanks for the help @westonruter it is very much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Routing Handling URLs
Projects
None yet
3 participants