Make WordPress Core

Changeset 35497


Ignore:
Timestamp:
11/03/2015 09:35:17 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Formatting: wp_make_link_relative() should return an empty string if no path is present in the link.

Props bcworkz, MikeHansenMe, chriscct7, SergeyBiryukov.
Fixes #26819.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r35479 r35497  
    36223622 */
    36233623function wp_make_link_relative( $link ) {
    3624     return preg_replace( '|^(https?:)?//[^/]+(/.*)|i', '$2', $link );
     3624    return preg_replace( '|^(https?:)?//[^/]+(/?.*)|i', '$2', $link );
    36253625}
    36263626
  • trunk/tests/phpunit/tests/link.php

    r35244 r35497  
    305305    }
    306306
    307     public function test_wp_make_link_relative_with_http_scheme() {
    308         $link = 'http://example.com/this-is-a-test-http-url/';
    309         $relative_link = wp_make_link_relative( $link );
    310         $this->assertEquals( '/this-is-a-test-http-url/', $relative_link );
    311     }
    312 
    313     public function test_wp_make_link_relative_with_https_scheme() {
    314         $link = 'https://example.com/this-is-a-test-https-url/';
    315         $relative_link = wp_make_link_relative( $link );
    316         $this->assertEquals( '/this-is-a-test-https-url/', $relative_link );
    317     }
    318 
    319     /**
    320      * @ticket 30373
    321      */
    322     public function test_wp_make_link_relative_with_no_scheme() {
    323         $link = '//example.com/this-is-a-test-schemeless-url/';
    324         $relative_link = wp_make_link_relative( $link );
    325         $this->assertEquals( '/this-is-a-test-schemeless-url/', $relative_link );
    326     }
    327 
    328     /**
    329      * @ticket 30373
    330      */
    331     public function test_wp_make_link_relative_should_retain_URL_param_that_is_also_a_URL() {
    332         $link = 'https://example.com/this-is-a-test/?redirect=https://example.org/a-different-test-post/';
    333         $relative_link = wp_make_link_relative( $link );
    334         $this->assertEquals( '/this-is-a-test/?redirect=https://example.org/a-different-test-post/', $relative_link );
    335     }
    336 
    337307    /**
    338308     * @ticket 30910
Note: See TracChangeset for help on using the changeset viewer.