#30373 closed defect (bug) (fixed)
wp_make_link_relative() isn't handling already relative urls
Reported by: | dd32 | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 4.1 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
#30372 added a unit test to show wp_make_link_relative()
working, so I took a look and spotted a few problems with the function:
- It doesn't handle schemeless url's
- It doesn't handle relative URL's with a URL in a parameter.
This example shows both failings:
var_dump( wp_make_link_relative( "//something.com/blah/blah?blah=http://example.com/ex" ) );
resulting in //something.com/blah/blah?blah=/ex
Attachments (3)
Change History (15)
#3
@
10 years ago
- Keywords needs-patch added; has-patch removed
voldemortensen - Thanks for the patch. Nitpick: can you separate the tests into three separate methods with more descriptive names, and put a @group 30373
annotation on the schemeless test, since that's the one actually fixed by this patch?
It looks like you are resolving the URL parameter issue with the ^
flag to mark the beginning of the string - is that right? Could you write a test for it?
#4
@
10 years ago
- Keywords has-patch added; needs-patch removed
boonebgorges - made a patch with your suggestions.
#5
@
10 years ago
30373.patch fixes the annotations (sorry, I meant @ticket
:) )
This looks good to me, but I'll let dd32 make the final call.
This ticket was mentioned in Slack in #core by voldemortensen. View the logs.
10 years ago
#8
@
10 years ago
- Summary changed from wp_make_link_relative() isn't to wp_make_link_relative() isn't handling already relative urls
#9
@
10 years ago
Just curious why the regex was changed from //
to \/\/
? Other than looking more like a W, /
isn't a special character in regex (As long as it's not also the delimiter, which in this case is |
)
Other than that, looks good to me.
#10
@
10 years ago
- Milestone changed from Awaiting Review to 4.1
I wondered the same thing about the unnecessary escaping. I love *W*ordPress as much as the next guy, but....
30373.diff fixes all these issues. It also fixes #30372 and includes more comprehensive unit tests.