General: Replace all esc_url_raw() calls in core with sanitize_url().

This aims to improve performance by calling `sanitize_url()` directly, instead of the `esc_url_raw()` wrapper. As of WordPress 6.1, `sanitize_url()` is the recommended function for sanitizing a URL for database or redirect usage.

Follow-up to [11383], [13096], [51597], [53452].

Props benjgrolleau, peterwilsoncc, SergeyBiryukov.
Fixes #55852.

git-svn-id: https://develop.svn.wordpress.org/trunk@53455 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-06-01 18:12:25 +00:00
parent c59af567e5
commit b316c8b25f
39 changed files with 87 additions and 87 deletions

View File

@@ -56,7 +56,7 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase {
),
parse_url( $url )
);
$this->assertSame( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url_raw( $url ) );
$this->assertSame( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', sanitize_url( $url ) );
$this->assertSame( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url( $url ) );
}
@@ -69,9 +69,9 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase {
}
public function test_encoding() {
$this->assertSame( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', sanitize_url( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', sanitize_url( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', sanitize_url( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
$this->assertSame( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
@@ -190,7 +190,7 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase {
*/
public function test_reserved_characters() {
$url = "http://example.com/:@-._~!$&'()*+,=;:@-._~!$&'()*+,=:@-._~!$&'()*+,==?/?:@-._~!$%27()*+,;=/?:@-._~!$%27()*+,;==#/?:@-._~!$&'()*+,;=";
$this->assertSame( $url, esc_url_raw( $url ) );
$this->assertSame( $url, sanitize_url( $url ) );
}
/**
@@ -245,7 +245,7 @@ EOT;
* @ticket 28015
*/
public function test_invalid_charaters() {
$this->assertEmpty( esc_url_raw( '"^<>{}`' ) );
$this->assertEmpty( sanitize_url( '"^<>{}`' ) );
}
/**

View File

@@ -144,8 +144,8 @@ class Tests_Link_ThemeFile extends WP_UnitTestCase {
$uri = get_theme_file_uri( $file );
$parent_uri = get_parent_theme_file_uri( $file );
$this->assertSame( esc_url_raw( $uri ), $uri );
$this->assertSame( esc_url_raw( $parent_uri ), $parent_uri );
$this->assertSame( sanitize_url( $uri ), $uri );
$this->assertSame( sanitize_url( $parent_uri ), $parent_uri );
}
public function data_theme_files() {

View File

@@ -1239,7 +1239,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
$result = rest_get_server()->serve_request( '/' );
$headers = rest_get_server()->sent_headers;
$this->assertSame( '<' . esc_url_raw( $api_root ) . '>; rel="https://api.w.org/"', $headers['Link'] );
$this->assertSame( '<' . sanitize_url( $api_root ) . '>; rel="https://api.w.org/"', $headers['Link'] );
}
public function test_nocache_headers_on_authenticated_requests() {