-
Notifications
You must be signed in to change notification settings - Fork 82
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
Allow regular expression parsing if the redirect target is a valid URL #395
Conversation
@benlk thanks for the PR! Could you please fill out the PR template with description, changelog, and credits information so that we can properly review and merge this? |
4708e63
to
3a5e71a
Compare
16a5fba
to
30c4c84
Compare
@benlk I took some liberties while testing this out. I re-ordered the commits to make sure the tests were failing against the unchanged code but they were passing, see the action run. I subsequently pushed some failing tests in 30c4c84, which did fail against the unchanged code, see the action run I finally pushed the fix (the new commit hash is 5e7bb7e) and the action is now passing, see the action run So... Are you able to confirm my updates to the test are testing the correct things? I'll review the changes in the mean time. |
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.
These changes look good to me, I think this is good to merge once Ben validates my updates to the tests.
The changes look good to me as well. The revised tests appear to be testing what was intended. |
I have no idea why the validation bot is failing to pick up the descriptions so ignoring the issue and merging regardless. |
Description of the Change
#269 reported a bug in the handling of regex redirects with a URL target: the URLs were being prefixed with a
/
.#279 fixed #269 by excluding the section of code that prepends URLs with
/
from being applied if the redirect target was a valid URL:safe-redirect-manager/inc/classes/class-srm-redirect.php
Lines 225 to 229 in cb1c045
Unfortunately, this also excluded the code that applies the regular expression to the redirect target URL. If the redirect target was a URL, the final
preg_replace
was no longer applied.This fix separates the prefix-with-
/
behavior from regex parsing by separating the conditionals.Closes #380
How to test the Change
Test cases, all with regular expressions:
/test/(.*)
tohttps://example.org/$1
with/test/1234
should go tohttps://example.org/1234/
(Regex pattern replacement fails if destination is absolute url. #380)/test/(.*)
to/$1
with/test/1234/
should go to/1234/
(go|be)\/h{0,}$
to/404-regex
with/be/hhhh
should go to/404-regex
(Regex redirects without leading/
are buggy #269)(go|be)\/h{0,}$
tohttp://xu-osp-plugins.local/404-regex
with/be/hhhh
should go tohttp://xu-osp-plugins.local/404-regex
(Regex redirects without leading/
are buggy #269)Changelog Entry
Credits
Props @benlk @peterwilsoncc
Checklist: