Changeset 36444
- Timestamp:
- 02/02/2016 03:10:09 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/pluggable.php (modified) (1 diff)
-
tests/phpunit/tests/formatting/redirect.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r36314 r36444 1337 1337 return $default; 1338 1338 1339 // Reject if scheme isset but host is not. This catches urls like https:host.com for which parse_url does not set the host field.1340 if ( isset($lp['scheme']) && !isset($lp['host']) )1339 // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field. 1340 if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) { 1341 1341 return $default; 1342 } 1343 1344 // Reject malformed components parse_url() can return on odd inputs. 1345 foreach ( array( 'user', 'pass', 'host' ) as $component ) { 1346 if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) { 1347 return $default; 1348 } 1349 } 1342 1350 1343 1351 $wpp = parse_url(home_url()); -
trunk/tests/phpunit/tests/formatting/redirect.php
r33707 r36444 4 4 * @group pluggable 5 5 * @group formatting 6 * @group redirect 6 7 */ 7 8 class Tests_Formatting_Redirect extends WP_UnitTestCase { 9 function setUp() { 10 add_filter( 'home_url', array( $this, 'home_url' ) ); 11 } 12 13 function tearDown() { 14 remove_filter( 'home_url', array( $this, 'home_url' ) ); 15 } 16 17 function home_url() { 18 return 'http://example.com/'; 19 } 20 8 21 function test_wp_sanitize_redirect() { 9 22 $this->assertEquals('http://example.com/watchthelinefeedgo', wp_sanitize_redirect('http://example.com/watchthelinefeed%0Ago')); … … 21 34 $this->assertEquals('http://example.com/@username', wp_sanitize_redirect('http://example.com/@username')); 22 35 } 36 37 /** 38 * @dataProvider valid_url_provider 39 */ 40 function test_wp_validate_redirect_valid_url( $url, $expected ) { 41 $this->assertEquals( $expected, wp_validate_redirect( $url ) ); 42 } 43 44 /** 45 * @dataProvider invalid_url_provider 46 */ 47 function test_wp_validate_redirect_invalid_url( $url ) { 48 $this->assertEquals( false, wp_validate_redirect( $url, false ) ); 49 } 50 51 function valid_url_provider() { 52 return array( 53 array( 'http://example.com', 'http://example.com' ), 54 array( 'http://example.com/', 'http://example.com/' ), 55 array( 'https://example.com/', 'https://example.com/' ), 56 array( '//example.com', 'http://example.com' ), 57 array( '//example.com/', 'http://example.com/' ), 58 array( 'http://example.com/?foo=http://example.com/', 'http://example.com/?foo=http://example.com/' ), 59 array( 'http://[email protected]/', 'http://[email protected]/' ), 60 array( 'http://user:@example.com/', 'http://user:@example.com/' ), 61 array( 'http://user:[email protected]/', 'http://user:[email protected]/' ), 62 ); 63 } 64 65 function invalid_url_provider() { 66 return array( 67 // parse_url() fails 68 array( '' ), 69 array( 'http://:' ), 70 71 // non-safelisted domain 72 array( 'http://non-safelisted.example/' ), 73 74 // unsupported schemes 75 array( 'data:text/plain;charset=utf-8,Hello%20World!' ), 76 array( 'file:///etc/passwd' ), 77 array( 'ftp://example.com/' ), 78 79 // malformed input 80 array( 'http:example.com' ), 81 array( 'http:80' ), 82 array( 'http://example.com:1234:5678/' ), 83 array( 'http://user:pa:[email protected]/' ), 84 85 array( 'http://user@@example.com' ), 86 array( 'http://user@:example.com' ), 87 array( 'http://[email protected]' ), 88 array( 'http://user@?example.com' ), 89 array( 'http://user#@example.com' ), 90 array( 'http://user@#example.com' ), 91 92 array( 'http://user@@example.com/' ), 93 array( 'http://user@:example.com/' ), 94 array( 'http://[email protected]/' ), 95 array( 'http://user@?example.com/' ), 96 array( 'http://user#@example.com/' ), 97 array( 'http://user@#example.com/' ), 98 99 array( 'http://user:pass@@example.com' ), 100 array( 'http://user:pass@:example.com' ), 101 array( 'http://user:[email protected]' ), 102 array( 'http://user:pass@?example.com' ), 103 array( 'http://user:pass#@example.com' ), 104 array( 'http://user:pass@#example.com' ), 105 106 array( 'http://user:pass@@example.com/' ), 107 array( 'http://user:pass@:example.com/' ), 108 array( 'http://user:[email protected]/' ), 109 array( 'http://user:pass@?example.com/' ), 110 array( 'http://user:pass#@example.com/' ), 111 array( 'http://user:pass@#example.com/' ), 112 113 array( 'http://user.pass@@example.com' ), 114 array( 'http://user.pass@:example.com' ), 115 array( 'http://[email protected]' ), 116 array( 'http://user.pass@?example.com' ), 117 array( 'http://user.pass#@example.com' ), 118 array( 'http://user.pass@#example.com' ), 119 120 array( 'http://user.pass@@example.com/' ), 121 array( 'http://user.pass@:example.com/' ), 122 array( 'http://[email protected]/' ), 123 array( 'http://user.pass@?example.com/' ), 124 array( 'http://user.pass#@example.com/' ), 125 array( 'http://user.pass@#example.com/' ), 126 ); 127 } 23 128 }
Note: See TracChangeset
for help on using the changeset viewer.