Changeset 35369
- Timestamp:
- 10/23/2015 05:53:05 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-http.php
r34585 r35369 689 689 * A wrapper for PHP's parse_url() function that handles edgecases in < PHP 5.4.7 690 690 * 691 * PHP 5.4.7 expanded parse_url()'s ability to handle non-absolute url's, including692 * schemeless and relative url's with :// in the path, this works around those693 * limitations providing a standard output on PHP 5.2~5.4+.694 *695 * Error suppression is used as prior to PHP 5.3.3, an E_WARNING would be generated696 * when URL parsing failed.697 *698 * @since 4.1.0699 *700 * @static701 691 * @access protected 692 * @deprecated 4.4.0 See wp_parse_url() 702 693 * 703 694 * @param string $url The URL to parse. … … 706 697 */ 707 698 protected static function parse_url( $url ) { 708 $parts = @parse_url( $url ); 709 if ( ! $parts ) { 710 // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path 711 if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) { 712 // Since we know it's a relative path, prefix with a scheme/host placeholder and try again 713 if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) { 714 return $parts; 715 } 716 // Remove the placeholder values 717 unset( $parts['scheme'], $parts['host'] ); 718 } else { 719 return $parts; 720 } 721 } 722 723 // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field 724 if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) { 725 list( $parts['host'], $slashless_path ) = explode( '/', substr( $parts['path'], 2 ), 2 ); 726 $parts['path'] = "/{$slashless_path}"; 727 } 728 729 return $parts; 699 _deprecated_function( __METHOD__, '4.4.0', 'wp_parse_url()' ); 700 return wp_parse_url( $url ); 730 701 } 731 702 … … 748 719 return $maybe_relative_path; 749 720 750 if ( ! $url_parts = WP_Http::parse_url( $url ) ) {721 if ( ! $url_parts = wp_parse_url( $url ) ) { 751 722 return $maybe_relative_path; 752 723 } 753 724 754 if ( ! $relative_url_parts = WP_Http::parse_url( $maybe_relative_path ) ) {725 if ( ! $relative_url_parts = wp_parse_url( $maybe_relative_path ) ) { 755 726 return $maybe_relative_path; 756 727 } -
trunk/src/wp-includes/http-functions.php
r35170 r35369 613 613 return $queried[ $host ]; 614 614 } 615 616 /** 617 * A wrapper for PHP's parse_url() function that handles edgecases in < PHP 5.4.7 618 * 619 * PHP 5.4.7 expanded parse_url()'s ability to handle non-absolute url's, including 620 * schemeless and relative url's with :// in the path, this works around those 621 * limitations providing a standard output on PHP 5.2~5.4+. 622 * 623 * Error suppression is used as prior to PHP 5.3.3, an E_WARNING would be generated 624 * when URL parsing failed. 625 * 626 * @since 4.4.0 627 * 628 * @param string $url The URL to parse. 629 * @return bool|array False on failure; Array of URL components on success; 630 * See parse_url()'s return values. 631 */ 632 function wp_parse_url( $url ) { 633 $parts = @parse_url( $url ); 634 if ( ! $parts ) { 635 // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path 636 if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) { 637 // Since we know it's a relative path, prefix with a scheme/host placeholder and try again 638 if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) { 639 return $parts; 640 } 641 // Remove the placeholder values 642 unset( $parts['scheme'], $parts['host'] ); 643 } else { 644 return $parts; 645 } 646 } 647 648 // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field 649 if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) { 650 $path_parts = explode( '/', substr( $parts['path'], 2 ), 2 ); 651 $parts['host'] = $path_parts[0]; 652 if ( isset( $path_parts[1] ) ) { 653 $parts['path'] = '/' . $path_parts[1]; 654 } else { 655 unset( $parts['path'] ); 656 } 657 } 658 659 return $parts; 660 } -
trunk/tests/phpunit/tests/http/http.php
r34123 r35369 71 71 * @dataProvider parse_url_testcases 72 72 */ 73 function test_parse_url( $url, $expected ) { 74 if ( ! is_callable( array( 'WP_HTTP_Testable', 'parse_url' ) ) ) { 75 $this->markTestSkipped( "This version of WP_HTTP doesn't support WP_HTTP::parse_url()" ); 76 return; 77 } 78 $actual = WP_HTTP_Testable::parse_url( $url ); 73 function test_wp_parse_url( $url, $expected ) { 74 $actual = wp_parse_url( $url ); 79 75 $this->assertEquals( $expected, $actual ); 80 76 } … … 93 89 array( 'http://example.com/http://example.net/', array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/http://example.net/' ) ), 94 90 array( '/path/http://example.net/', array( 'path' => '/path/http://example.net/' ) ), 91 92 // < PHP 5.4.7: IPv6 literals in schemeless URLs are handled incorrectly. 93 array( '//[::FFFF::127.0.0.1]/', array( 'host' => '[::FFFF::127.0.0.1]', 'path' => '/' ) ), 94 95 95 // PHP's parse_url() calls this an invalid url, we handle it as a path 96 96 array( '/://example.com/', array( 'path' => '/://example.com/' ) ), … … 104 104 } 105 105 } 106 107 /**108 * A Wrapper of WP_Http to make parse_url() publicaly accessible for testing purposes.109 */110 class WP_HTTP_Testable extends WP_Http {111 public static function parse_url( $url ) {112 return parent::parse_url( $url );113 }114 }
Note: See TracChangeset
for help on using the changeset viewer.