safe-redirect-manager icon indicating copy to clipboard operation
safe-redirect-manager copied to clipboard

Regex pattern replacement fails if destination is absolute url.

Open earthlingdavey opened this issue 1 year ago • 1 comments

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

  1. Create a redirect with source /test/(.*)
  2. Enable Regular Expressions true
  3. Redirect to https://google.com/$1
  4. Visit /test/abc Expected destination is https://google.com/abc actual destination is https://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

earthlingdavey avatar May 07 '24 13:05 earthlingdavey

I can confirm this bug

guillaumemolter avatar May 20 '24 18:05 guillaumemolter

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

benlk avatar Sep 13 '24 22:09 benlk

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

benlk avatar Sep 16 '24 22:09 benlk