Opened 11 years ago
Closed 9 years ago
#26819 closed defect (bug) (fixed)
wp_make_link_relative() returns domain name instead of zero length string path when no path present
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Formatting | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
wp_make_link_relative() simply returns the URL passed to it when the URL has no path, just a domain name. Instead, it should return a zero length string.
A URL with a path of '/' correctly returns '/'.
Incorrect: var_dump( wp_make_link_relative( 'http://www.wordpress.org' ) ) displays "string(24) "http://www.wordpress.org"
Correct: var_dump( wp_make_link_relative( 'http://www.wordpress.org/' ) ) displays string(1) "/"
Workaround: for my purposes, parse_url( $home_url, PHP_URL_PATH ) does all that I need, but wp_make_link_relative() would still be useful when a Query or Fragment is present in the URL.
Attachments (3)
Change History (8)
#2
@
11 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
Huh, I never heard of wp_make_link_relative(). Looks like it hasn't been used anywhere in core since WordPress 2.5.
I am fine with fixing this but we will need some unit tests, I think.
Making the slash in the match expression optional does the trick.