#30373 closed defect (bug) (fixed)
wp_make_link_relative() isn't handling already relative urls
| Reported by: | dd32 | Owned by: | boonebgorges |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.1 |
| Component: | General | Version: | 4.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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
@
12 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
@
12 years ago
- Keywords has-patch added; needs-patch removed
boonebgorges - made a patch with your suggestions.
#5
@
12 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.
12 years ago
#8
@
12 years ago
- Summary wp_make_link_relative() isn't → wp_make_link_relative() isn't handling already relative urls
#9
@
12 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
30373.diff fixes all these issues. It also fixes #30372 and includes more comprehensive unit tests.