Changeset 34675 for trunk/tests/phpunit/tests/formatting/EscUrl.php
- Timestamp:
- 09/29/2015 01:00:17 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/formatting/EscUrl.php
r34674 r34675 41 41 42 42 function test_all_url_parts() { 43 $url = 'https://user:pass@host.example.com:1234/path;p=1?query=2&r[]=3#fragment'; 43 $url = 'https://user:password@host.example.com:1234/path;p=1?q=2&r=3#fragment'; 44 $this->assertEquals( $url, esc_url_raw( $url ) ); 44 45 45 $this->assertEquals( array( 46 'scheme' => 'https', 47 'host' => 'host.example.com', 48 'port' => 1234, 49 'user' => 'user', 50 'pass' => 'pass', 51 'path' => '/path;p=1', 52 'query' => 'query=2&r[]=3', 53 'fragment' => 'fragment', 54 ), parse_url( $url ) ); 55 $this->assertEquals( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url_raw( $url ) ); 56 $this->assertEquals( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url( $url ) ); 57 } 46 $this->assertEquals( 'https://user:password@host.example.com:1234/path;p=1?q=2&r=3#fragment', esc_url( $url ) ); 58 47 59 function test_all_url_parts_ipv6() { 60 $url = 'https://user:pass@[::FFFF::127.0.0.1]:1234/path;p=1?query=2&r[]=3#fragment'; 61 62 $this->assertEquals( array( 63 'scheme' => 'https', 64 'host' => '[::FFFF::127.0.0.1]', 65 'port' => 1234, 66 'user' => 'user', 67 'pass' => 'pass', 68 'path' => '/path;p=1', 69 'query' => 'query=2&r[]=3', 70 'fragment' => 'fragment', 71 ), parse_url( $url ) ); 72 $this->assertEquals( 'https://user:pass@[::FFFF::127.0.0.1]:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url_raw( $url ) ); 73 $this->assertEquals( 'https://user:pass@[::FFFF::127.0.0.1]:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url( $url ) ); 48 $this->assertEquals( 'http://example.com?foo', esc_url( 'http://example.com?foo' ) ); 74 49 } 75 50 76 51 function test_bare() { 77 $this->assertEquals( 'http://example.com?foo', esc_url( 'example.com?foo' ) );78 52 $this->assertEquals( 'http://example.com', esc_url( 'example.com' ) ); 79 53 $this->assertEquals( 'http://localhost', esc_url( 'localhost' ) ); … … 153 127 154 128 /** 155 * @ticket 16859156 */157 function test_square_brackets() {158 $this->assertEquals( '/example.php?one%5B%5D=two', esc_url( '/example.php?one[]=two' ) );159 $this->assertEquals( '?foo%5Bbar%5D=baz', esc_url( '?foo[bar]=baz' ) );160 $this->assertEquals( '//example.com/?foo%5Bbar%5D=baz', esc_url( '//example.com/?foo[bar]=baz' ) );161 $this->assertEquals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'example.com/?foo[bar]=baz' ) );162 $this->assertEquals( 'http://localhost?foo%5Bbar%5D=baz', esc_url( 'localhost?foo[bar]=baz' ) );163 $this->assertEquals( 'http://user:pass@localhost/?foo%5Bbar%5D=baz', esc_url( 'http://user:pass@localhost/?foo[bar]=baz' ) );164 $this->assertEquals( 'http://localhost?foo%5Bbar%5D=baz', esc_url( 'localhost?foo[bar]=baz' ) );165 $this->assertEquals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo[bar]=baz' ) );166 $this->assertEquals( 'http://example.com:1234/?foo%5Bbar%5D=baz', esc_url( 'http://example.com:1234/?foo[bar]=baz' ) );167 $this->assertEquals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo%5Bbar%5D=baz' ) );168 $this->assertEquals( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) );169 $this->assertEquals( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz' ) );170 }171 172 /**173 * @ticket 16859174 */175 function test_ipv6_hosts() {176 $this->assertEquals( '//[::127.0.0.1]', esc_url( '//[::127.0.0.1]' ) );177 $this->assertEquals( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) );178 $this->assertEquals( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) );179 $this->assertEquals( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) );180 181 // IPv6 with square brackets in the query? Why not.182 $this->assertEquals( '//[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( '//[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );183 $this->assertEquals( 'http://[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( 'http://[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );184 }185 186 /**187 * Courtesy of http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding188 */189 function test_reserved_characters() {190 $url = "http://example.com/:@-._~!$&'()*+,=;:@-._~!$&'()*+,=:@-._~!$&'()*+,==?/?:@-._~!$%27()*+,;=/?:@-._~!$%27()*+,;==#/?:@-._~!$&'()*+,;=";191 $this->assertEquals( $url, esc_url_raw( $url ) );192 }193 194 /**195 129 * @ticket 21974 196 130 */ … … 242 176 */ 243 177 function test_invalid_charaters() { 244 $this->assertEmpty( esc_url_raw('"^ <>{}`') );178 $this->assertEmpty( esc_url_raw('"^[]<>{}`') ); 245 179 } 246 180
Note: See TracChangeset
for help on using the changeset viewer.