diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index 411eaa8..68ea28b 100644
|
|
function tag_escape($tag_name) { |
3239 | 3239 | * @return string Absolute path. |
3240 | 3240 | */ |
3241 | 3241 | function wp_make_link_relative( $link ) { |
3242 | | return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link ); |
| 3242 | return preg_replace( '|^(https?:)?\/\/[^/]+(\/.*)|i', '$2', $link ); |
3243 | 3243 | } |
3244 | 3244 | |
3245 | 3245 | /** |
diff --git tests/phpunit/tests/link.php tests/phpunit/tests/link.php
index 9e3a39d..ec94d60 100644
|
|
class Tests_Link extends WP_UnitTestCase { |
256 | 256 | $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), true ) ); |
257 | 257 | $this->assertEmpty( get_adjacent_post( false, array(), false ) ); |
258 | 258 | } |
259 | | } |
260 | | No newline at end of file |
| 259 | |
| 260 | public function test_wp_make_link_relative_with_http_scheme() { |
| 261 | $link = 'http://example.com/this-is-a-test-http-url/'; |
| 262 | $relative_link = wp_make_link_relative( $link ); |
| 263 | $this->assertEquals( '/this-is-a-test-http-url/', $relative_link ); |
| 264 | } |
| 265 | |
| 266 | public function test_wp_make_link_relative_with_https_scheme() { |
| 267 | $link = 'https://example.com/this-is-a-test-https-url/'; |
| 268 | $relative_link = wp_make_link_relative( $link ); |
| 269 | $this->assertEquals( '/this-is-a-test-https-url/', $relative_link ); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * @ticket 30373 |
| 274 | */ |
| 275 | public function test_wp_make_link_relative_with_no_scheme() { |
| 276 | $link = '//example.com/this-is-a-test-schemeless-url/'; |
| 277 | $relative_link = wp_make_link_relative( $link ); |
| 278 | $this->assertEquals( '/this-is-a-test-schemeless-url/', $relative_link ); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * @ticket 30373 |
| 283 | */ |
| 284 | public function test_wp_make_link_relative_should_retain_URL_param_that_is_also_a_URL() { |
| 285 | $link = 'https://example.com/this-is-a-test/?redirect=https://example.org/a-different-test-post/'; |
| 286 | $relative_link = wp_make_link_relative( $link ); |
| 287 | $this->assertEquals( '/this-is-a-test/?redirect=https://example.org/a-different-test-post/', $relative_link ); |
| 288 | } |
| 289 | } |