Regex pattern replacement fails if destination is absolute url.
Describe the bug
When using regex pattern replacement, using $1 doesn't work as expected when the destination is an absolute url.
Steps to Reproduce
- Create a redirect with source
/test/(.*) - Enable Regular Expressions
true - Redirect to
https://google.com/$1 - Visit
/test/abcExpected destination ishttps://google.com/abcactual destination ishttps://google.com/1
Screenshots, screen recording, code snippet
NA
Environment information
NA
WordPress information
NA
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I can confirm this bug
I confirm this bug as well.
I think the error is here but will need to test next week:
https://github.com/10up/safe-redirect-manager/blob/cb1c04513b75736a0938208c5837b3ce51abdcba/inc/classes/class-srm-redirect.php#L225-L229
Using the example redirect:
from: /test/(.*)
to: https://example.org/$1
regex: true
https://github.com/10up/safe-redirect-manager/blob/cb1c04513b75736a0938208c5837b3ce51abdcba/inc/classes/class-srm-redirect.php#L225-L229
filter_var( $redirect_to, FILTER_VALIDATE_URL ) returns https://example.org/$1
! filter_var( $redirect_to, FILTER_VALIDATE_URL ) returns the Boolean opposite of a string, which since strings are truthy is false