Changeset 48937 for trunk/tests/phpunit/tests/formatting/EscUrl.php
- Timestamp:
- 09/02/2020 12:35:36 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/formatting/EscUrl.php
r47122 r48937 10 10 */ 11 11 function test_spaces() { 12 $this->assert Equals( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr WordPress' ) );13 $this->assert Equals( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr%20WordPress' ) );14 $this->assert Equals( 'http://example.com/Mr%20%20WordPress', esc_url( 'http://example.com/Mr%20%20WordPress' ) );15 $this->assert Equals( 'http://example.com/Mr+WordPress', esc_url( 'http://example.com/Mr+WordPress' ) );16 $this->assert Equals( 'http://example.com/Mr+WordPress', esc_url( ' http://example.com/Mr+WordPress' ) );17 18 $this->assert Equals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one two three&bar=four' ) );19 $this->assert Equals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one%20two%20three&bar=four' ) );12 $this->assertSame( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr WordPress' ) ); 13 $this->assertSame( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr%20WordPress' ) ); 14 $this->assertSame( 'http://example.com/Mr%20%20WordPress', esc_url( 'http://example.com/Mr%20%20WordPress' ) ); 15 $this->assertSame( 'http://example.com/Mr+WordPress', esc_url( 'http://example.com/Mr+WordPress' ) ); 16 $this->assertSame( 'http://example.com/Mr+WordPress', esc_url( ' http://example.com/Mr+WordPress' ) ); 17 18 $this->assertSame( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one two three&bar=four' ) ); 19 $this->assertSame( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one%20two%20three&bar=four' ) ); 20 20 } 21 21 22 22 function test_bad_characters() { 23 $this->assert Equals( 'http://example.com/watchthelinefeedgo', esc_url( 'http://example.com/watchthelinefeed%0Ago' ) );24 $this->assert Equals( 'http://example.com/watchthelinefeedgo', esc_url( 'http://example.com/watchthelinefeed%0ago' ) );25 $this->assert Equals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0Dgo' ) );26 $this->assert Equals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0dgo' ) );23 $this->assertSame( 'http://example.com/watchthelinefeedgo', esc_url( 'http://example.com/watchthelinefeed%0Ago' ) ); 24 $this->assertSame( 'http://example.com/watchthelinefeedgo', esc_url( 'http://example.com/watchthelinefeed%0ago' ) ); 25 $this->assertSame( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0Dgo' ) ); 26 $this->assertSame( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0dgo' ) ); 27 27 // Nesting checks. 28 $this->assert Equals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0%0ddgo' ) );29 $this->assert Equals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0%0DDgo' ) );30 $this->assert Equals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0DAD' ) );31 $this->assert Equals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0ADA' ) );32 $this->assert Equals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0DAd' ) );33 $this->assert Equals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0ADa' ) );28 $this->assertSame( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0%0ddgo' ) ); 29 $this->assertSame( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0%0DDgo' ) ); 30 $this->assertSame( 'http://example.com/', esc_url( 'http://example.com/%0%0%0DAD' ) ); 31 $this->assertSame( 'http://example.com/', esc_url( 'http://example.com/%0%0%0ADA' ) ); 32 $this->assertSame( 'http://example.com/', esc_url( 'http://example.com/%0%0%0DAd' ) ); 33 $this->assertSame( 'http://example.com/', esc_url( 'http://example.com/%0%0%0ADa' ) ); 34 34 } 35 35 36 36 function test_relative() { 37 $this->assert Equals( '/example.php', esc_url( '/example.php' ) );38 $this->assert Equals( 'example.php', esc_url( 'example.php' ) );39 $this->assert Equals( '#fragment', esc_url( '#fragment' ) );40 $this->assert Equals( '?foo=bar', esc_url( '?foo=bar' ) );37 $this->assertSame( '/example.php', esc_url( '/example.php' ) ); 38 $this->assertSame( 'example.php', esc_url( 'example.php' ) ); 39 $this->assertSame( '#fragment', esc_url( '#fragment' ) ); 40 $this->assertSame( '?foo=bar', esc_url( '?foo=bar' ) ); 41 41 } 42 42 … … 44 44 $url = 'https://user:pass@host.example.com:1234/path;p=1?query=2&r[]=3#fragment'; 45 45 46 $this->assert Equals(46 $this->assertSame( 47 47 array( 48 48 'scheme' => 'https', … … 57 57 parse_url( $url ) 58 58 ); 59 $this->assert Equals( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url_raw( $url ) );60 $this->assert Equals( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url( $url ) );59 $this->assertSame( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url_raw( $url ) ); 60 $this->assertSame( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url( $url ) ); 61 61 } 62 62 63 63 function test_bare() { 64 $this->assert Equals( 'http://example.com?foo', esc_url( 'example.com?foo' ) );65 $this->assert Equals( 'http://example.com', esc_url( 'example.com' ) );66 $this->assert Equals( 'http://localhost', esc_url( 'localhost' ) );67 $this->assert Equals( 'http://example.com/foo', esc_url( 'example.com/foo' ) );68 $this->assert Equals( 'http://баба.org/баба', esc_url( 'баба.org/баба' ) );64 $this->assertSame( 'http://example.com?foo', esc_url( 'example.com?foo' ) ); 65 $this->assertSame( 'http://example.com', esc_url( 'example.com' ) ); 66 $this->assertSame( 'http://localhost', esc_url( 'localhost' ) ); 67 $this->assertSame( 'http://example.com/foo', esc_url( 'example.com/foo' ) ); 68 $this->assertSame( 'http://баба.org/баба', esc_url( 'баба.org/баба' ) ); 69 69 } 70 70 71 71 function test_encoding() { 72 $this->assert Equals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );73 $this->assert Equals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );74 $this->assert Equals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );75 76 $this->assert Equals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );77 $this->assert Equals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );78 $this->assert Equals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );72 $this->assertSame( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) ); 73 $this->assertSame( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) ); 74 $this->assertSame( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) ); 75 76 $this->assertSame( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) ); 77 $this->assertSame( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) ); 78 $this->assertSame( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) ); 79 79 80 80 $param = urlencode( 'http://example.com/?one=1&two=2' ); 81 $this->assert Equals( "http://example.com?url={$param}", esc_url( "http://example.com?url={$param}" ) );81 $this->assertSame( "http://example.com?url={$param}", esc_url( "http://example.com?url={$param}" ) ); 82 82 } 83 83 84 84 function test_protocol() { 85 $this->assert Equals( 'http://example.com', esc_url( 'http://example.com' ) );86 $this->assert Equals( '', esc_url( 'nasty://example.com/' ) );87 $this->assert Equals(85 $this->assertSame( 'http://example.com', esc_url( 'http://example.com' ) ); 86 $this->assertSame( '', esc_url( 'nasty://example.com/' ) ); 87 $this->assertSame( 88 88 '', 89 89 esc_url( … … 94 94 ) 95 95 ); 96 $this->assert Equals(96 $this->assertSame( 97 97 '', 98 98 esc_url( … … 103 103 ) 104 104 ); 105 $this->assert Equals(105 $this->assertSame( 106 106 'https://example.com', 107 107 esc_url( … … 115 115 116 116 foreach ( wp_allowed_protocols() as $scheme ) { 117 $this->assert Equals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com" ), $scheme );118 $this->assert Equals(117 $this->assertSame( "{$scheme}://example.com", esc_url( "{$scheme}://example.com" ), $scheme ); 118 $this->assertSame( 119 119 "{$scheme}://example.com", 120 120 esc_url( … … 129 129 130 130 $this->assertTrue( ! in_array( 'data', wp_allowed_protocols(), true ) ); 131 $this->assert Equals( '', esc_url( 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D' ) );131 $this->assertSame( '', esc_url( 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D' ) ); 132 132 133 133 $this->assertTrue( ! in_array( 'foo', wp_allowed_protocols(), true ) ); 134 $this->assert Equals(134 $this->assertSame( 135 135 'foo://example.com', 136 136 esc_url( … … 148 148 */ 149 149 function test_protocol_case() { 150 $this->assert Equals( 'http://example.com', esc_url( 'HTTP://example.com' ) );151 $this->assert Equals( 'http://example.com', esc_url( 'Http://example.com' ) );150 $this->assertSame( 'http://example.com', esc_url( 'HTTP://example.com' ) ); 151 $this->assertSame( 'http://example.com', esc_url( 'Http://example.com' ) ); 152 152 } 153 153 154 154 function test_display_extras() { 155 $this->assert Equals( 'http://example.com/'quoted'', esc_url( 'http://example.com/\'quoted\'' ) );156 $this->assert Equals( 'http://example.com/\'quoted\'', esc_url( 'http://example.com/\'quoted\'', null, 'notdisplay' ) );155 $this->assertSame( 'http://example.com/'quoted'', esc_url( 'http://example.com/\'quoted\'' ) ); 156 $this->assertSame( 'http://example.com/\'quoted\'', esc_url( 'http://example.com/\'quoted\'', null, 'notdisplay' ) ); 157 157 } 158 158 159 159 function test_non_ascii() { 160 $this->assert Equals( 'http://example.org/баба', esc_url( 'http://example.org/баба' ) );161 $this->assert Equals( 'http://баба.org/баба', esc_url( 'http://баба.org/баба' ) );162 $this->assert Equals( 'http://müller.com/', esc_url( 'http://müller.com/' ) );160 $this->assertSame( 'http://example.org/баба', esc_url( 'http://example.org/баба' ) ); 161 $this->assertSame( 'http://баба.org/баба', esc_url( 'http://баба.org/баба' ) ); 162 $this->assertSame( 'http://müller.com/', esc_url( 'http://müller.com/' ) ); 163 163 } 164 164 165 165 function test_feed() { 166 $this->assert Equals( '', esc_url( 'feed:javascript:alert(1)' ) );167 $this->assert Equals( '', esc_url( 'feed:javascript:feed:alert(1)' ) );168 $this->assert Equals( '', esc_url( 'feed:feed:javascript:alert(1)' ) );169 $this->assert Equals( 'feed:feed:alert(1)', esc_url( 'feed:feed:alert(1)' ) );170 $this->assert Equals( 'feed:http://wordpress.org/feed/', esc_url( 'feed:http://wordpress.org/feed/' ) );166 $this->assertSame( '', esc_url( 'feed:javascript:alert(1)' ) ); 167 $this->assertSame( '', esc_url( 'feed:javascript:feed:alert(1)' ) ); 168 $this->assertSame( '', esc_url( 'feed:feed:javascript:alert(1)' ) ); 169 $this->assertSame( 'feed:feed:alert(1)', esc_url( 'feed:feed:alert(1)' ) ); 170 $this->assertSame( 'feed:http://wordpress.org/feed/', esc_url( 'feed:http://wordpress.org/feed/' ) ); 171 171 } 172 172 … … 175 175 */ 176 176 function test_square_brackets() { 177 $this->assert Equals( '/example.php?one%5B%5D=two', esc_url( '/example.php?one[]=two' ) );178 $this->assert Equals( '?foo%5Bbar%5D=baz', esc_url( '?foo[bar]=baz' ) );179 $this->assert Equals( '//example.com/?foo%5Bbar%5D=baz', esc_url( '//example.com/?foo[bar]=baz' ) );180 $this->assert Equals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'example.com/?foo[bar]=baz' ) );181 $this->assert Equals( 'http://localhost?foo%5Bbar%5D=baz', esc_url( 'localhost?foo[bar]=baz' ) );182 $this->assert Equals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo[bar]=baz' ) );183 $this->assert Equals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo%5Bbar%5D=baz' ) );184 $this->assert Equals( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) );185 $this->assert Equals( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz' ) );177 $this->assertSame( '/example.php?one%5B%5D=two', esc_url( '/example.php?one[]=two' ) ); 178 $this->assertSame( '?foo%5Bbar%5D=baz', esc_url( '?foo[bar]=baz' ) ); 179 $this->assertSame( '//example.com/?foo%5Bbar%5D=baz', esc_url( '//example.com/?foo[bar]=baz' ) ); 180 $this->assertSame( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'example.com/?foo[bar]=baz' ) ); 181 $this->assertSame( 'http://localhost?foo%5Bbar%5D=baz', esc_url( 'localhost?foo[bar]=baz' ) ); 182 $this->assertSame( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo[bar]=baz' ) ); 183 $this->assertSame( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo%5Bbar%5D=baz' ) ); 184 $this->assertSame( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) ); 185 $this->assertSame( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz' ) ); 186 186 } 187 187 … … 191 191 function test_reserved_characters() { 192 192 $url = "http://example.com/:@-._~!$&'()*+,=;:@-._~!$&'()*+,=:@-._~!$&'()*+,==?/?:@-._~!$%27()*+,;=/?:@-._~!$%27()*+,;==#/?:@-._~!$&'()*+,;="; 193 $this->assert Equals( $url, esc_url_raw( $url ) );193 $this->assertSame( $url, esc_url_raw( $url ) ); 194 194 } 195 195 … … 198 198 */ 199 199 function test_protocol_relative_with_colon() { 200 $this->assert Equals( '//example.com/foo?foo=abc:def', esc_url( '//example.com/foo?foo=abc:def' ) );200 $this->assertSame( '//example.com/foo?foo=abc:def', esc_url( '//example.com/foo?foo=abc:def' ) ); 201 201 } 202 202 … … 213 213 $email_link = 'mailto:?body=' . rawurlencode( $body ); 214 214 $email_link = esc_url( $email_link ); 215 $this->assert Equals( 'mailto:?body=Hi%20there%2C%0A%0AI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );215 $this->assertSame( 'mailto:?body=Hi%20there%2C%0A%0AI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link ); 216 216 } 217 217 … … 228 228 $email_link = 'http://example.com/mailto:?body=' . rawurlencode( $body ); 229 229 $email_link = esc_url( $email_link ); 230 $this->assert Equals( 'http://example.com/mailto:?body=Hi%20there%2CI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );230 $this->assertSame( 'http://example.com/mailto:?body=Hi%20there%2CI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link ); 231 231 } 232 232 … … 239 239 $email_link = 'mailto:?body=' . $body; 240 240 $email_link = esc_url( $email_link ); 241 $this->assert Equals( 'mailto:?body=Hi%20there,%20I%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );241 $this->assertSame( 'mailto:?body=Hi%20there,%20I%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link ); 242 242 } 243 243 … … 253 253 */ 254 254 function test_ipv6_hosts() { 255 $this->assert Equals( '//[::127.0.0.1]', esc_url( '//[::127.0.0.1]' ) );256 $this->assert Equals( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) );257 $this->assert Equals( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) );258 $this->assert Equals( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) );255 $this->assertSame( '//[::127.0.0.1]', esc_url( '//[::127.0.0.1]' ) ); 256 $this->assertSame( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) ); 257 $this->assertSame( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) ); 258 $this->assertSame( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) ); 259 259 260 260 // IPv6 with square brackets in the query? Why not. 261 $this->assert Equals( '//[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( '//[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );262 $this->assert Equals( 'http://[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( 'http://[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );261 $this->assertSame( '//[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( '//[::FFFF::127.0.0.1]/?foo[bar]=baz' ) ); 262 $this->assertSame( 'http://[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( 'http://[::FFFF::127.0.0.1]/?foo[bar]=baz' ) ); 263 263 } 264 264
Note: See TracChangeset
for help on using the changeset viewer.