Prevent empty query var from causing false positive endpoint detection #5804
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Amends #5558. See #2204.
Thanks to @milindmore22 for pointing this out, there's a bug with in how the AMP endpoints are detected. In particular, when a non-AMP URL is request with an empty query var, e.g.
?foo=
, the result is the URL erroneously being identified as an AMP one. The reason for this is that I was removing the endpoint from the URL and then checking of the endpoint-removed URL was not equal to the original URL as a shortcut to identify an AMP URL. This, however, doesn't work becauseremove_query_var()
doesn't preserve the distinction between a query var with an empty value and one with no value:Notice how
?bar=
and?bar
both end up the same as?bar
when being passed intoremove_query_arg()
.So the fix is to check if the URL has the endpoint first, and then if it has it, proceed with removing it. This avoids the false positive.