Make WordPress Core

Ticket #30373: 30373.diff

File 30373.diff, 1.5 KB (added by voldemortensen, 10 years ago)
  • tests/phpunit/tests/link.php

     
    256256                $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), true ) );
    257257                $this->assertEmpty( get_adjacent_post( false, array(), false ) );
    258258        }
    259 }
    260  No newline at end of file
     259
     260        public function test_wp_make_link_relative() {
     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                $link = 'https://example.com/this-is-a-test-https-url/';
     266                $relative_link = wp_make_link_relative( $link );
     267                $this->assertEquals( '/this-is-a-test-https-url/', $relative_link );
     268
     269                $link = '//example.com/this-is-a-test-schemeless-url/';
     270                $relative_link = wp_make_link_relative( $link );
     271                $this->assertEquals( '/this-is-a-test-schemeless-url/', $relative_link );
     272        }
     273}
  • src/wp-includes/formatting.php

     
    32393239 * @return string Absolute path.
    32403240 */
    32413241function wp_make_link_relative( $link ) {
    3242         return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link );
     3242        return preg_replace( '|^(https?:)?\/\/[^/]+(\/.*)|i', '$2', $link );
    32433243}
    32443244
    32453245/**