Make WordPress Core

Changeset 55370


Ignore:
Timestamp:
02/21/2023 01:47:57 AM (4 years ago)
Author:
peterwilsoncc
Message:

HTTP API: Add fragment support to WP_Http::make_absolute_url().

Modifies WP_Http::make_absolute_url() to prevent it from dropping URL fragments, this in turn fixes the same issue for links_add_base_url().

Props costdev, sergeybiryukov, dshanske, schlessera, jrf, desrosj, dd32.
Fixes #56231.

Location:
trunk
Files:
2 edited

Legend:

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

    r55063 r55370  
    10141014                }
    10151015
     1016                // Add the fragment.
     1017                if ( ! empty( $relative_url_parts['fragment'] ) ) {
     1018                        $path .= '#' . $relative_url_parts['fragment'];
     1019                }
     1020
    10161021                return $absolute_path . '/' . ltrim( $path, '/' );
    10171022        }
  • trunk/tests/phpunit/tests/http/http.php

    r55029 r55370  
    1010
    1111        /**
     12         * @ticket 20434
     13         * @ticket 56231
     14         *
    1215         * @dataProvider make_absolute_url_testcases
    1316         *
    … …  
    6770                        // Schemeless URL's (not valid in HTTP Headers, but may be used elsewhere).
    6871                        array( '//example.com/sub/', 'https://example.net', 'https://example.com/sub/' ),
     72
     73                        // URLs with fragments.
     74                        array( '/path#frag', 'http://example.org/', 'http://example.org/path#frag' ),
     75                        array( '/path/#frag', 'http://example.org/', 'http://example.org/path/#frag' ),
     76                        array( '/path#frag&ment=1', 'http://example.org/', 'http://example.org/path#frag&ment=1' ),
     77                        array( '/path?query=string#frag', 'http://example.org/', 'http://example.org/path?query=string#frag' ),
     78                        array( '/path?query=string%23frag', 'http://example.org/', 'http://example.org/path?query=string%23frag' ),
    6979                );
    7080        }
Note: See TracChangeset for help on using the changeset viewer.