From 73d4c6cbf6fde7dd5651ffcb6bc6c92aeb407ede Mon Sep 17 00:00:00 2001
Date: Tue, 4 Oct 2016 02:07:02 +0200
Subject: [PATCH] Fix potential undefined notice on `$url[0]` in
wp_parse_url().
---
src/wp-includes/http.php | 4 +++-
tests/phpunit/tests/http/http.php | 18 ++++++++++++++++--
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/wp-includes/http.php b/src/wp-includes/http.php
index 8c26d57..1d18bc8 100644
a
|
b
|
function wp_parse_url( $url, $component = -1 ) { |
661 | 661 | $schemeless_with_colon = ( '//' === substr( $url, 0, 2 ) && false !== strpos( $url, ':' ) ); |
662 | 662 | |
663 | 663 | if ( false === $parts ) { |
| 664 | $url = strval( $url ); |
| 665 | |
664 | 666 | // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path. |
665 | | if ( '/' === $url[0] && ( false !== strpos( $url, '://' ) || true === $schemeless_with_colon ) ) { |
| 667 | if ( '' !== $url && '/' === $url[0] && ( false !== strpos( $url, '://' ) || true === $schemeless_with_colon ) ) { |
666 | 668 | if ( true === $schemeless_with_colon ) { |
667 | 669 | if ( PHP_URL_SCHEME === $component ) { |
668 | 670 | return null; |
diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php
index aede069..a3e80e5 100644
a
|
b
|
class Tests_HTTP_HTTP extends WP_UnitTestCase { |
132 | 132 | 'path' => '/path1/path2/file.php', |
133 | 133 | 'query' => 'q=a', |
134 | 134 | ) ), |
| 135 | |
| 136 | // Empty string or non-string passed in. |
| 137 | array( '', array( |
| 138 | 'path' => '', |
| 139 | ) ), |
| 140 | array( 123, array( |
| 141 | 'path' => '123', |
| 142 | ) ), |
135 | 143 | ); |
136 | 144 | /* |
137 | 145 | Untestable edge cases in various PHP: |
… |
… |
class Tests_HTTP_HTTP extends WP_UnitTestCase { |
215 | 223 | array( 'http://www.test.com/path1/path2/&q=a', PHP_URL_QUERY, 'q=a' ), |
216 | 224 | array( 'http://www.test.com/path1/path2/file.php&q=a', PHP_URL_PATH, '/path1/path2/file.php' ), |
217 | 225 | array( 'http://www.test.com/path1/path2/file.php&q=a', PHP_URL_QUERY, 'q=a' ), |
| 226 | |
| 227 | // Empty string or non-string passed in. |
| 228 | array( '', PHP_URL_PATH, '' ), |
| 229 | array( '', PHP_URL_QUERY, null ), |
| 230 | array( 123, PHP_URL_PORT, null ), |
| 231 | array( 123, PHP_URL_PATH, '123' ), |
218 | 232 | ); |
219 | 233 | } |
220 | 234 | |
… |
… |
class Tests_HTTP_HTTP extends WP_UnitTestCase { |
283 | 297 | array( 'http://example.com/', -1, array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/' ) ), |
284 | 298 | array( 'http://example.com/', PHP_URL_HOST, 'example.com' ), |
285 | 299 | array( 'http://example.com/', PHP_URL_USER, null ), |
286 | | array( 'http:///example.com', -1, false ), |
287 | | array( 'http:///example.com', PHP_URL_HOST, null ), |
| 300 | array( 'http:///example.com', -1, false ), // Malformed. |
| 301 | array( 'http:///example.com', PHP_URL_HOST, null ), // Malformed. |
288 | 302 | ); |
289 | 303 | } |
290 | 304 | |