MediaWiki REL1_33
wfUrlencodeTest.php
Go to the documentation of this file.
1<?php
2
10 # ### TESTS ##############################################################
11
15 public function testEncodingUrlWith( $input, $expected ) {
16 $this->verifyEncodingFor( 'Apache', $input, $expected );
17 }
18
22 public function testEncodingUrlWithMicrosoftIis7( $input, $expected ) {
23 $this->verifyEncodingFor( 'Microsoft-IIS/7', $input, $expected );
24 }
25
26 # ### HELPERS #############################################################
27
32 private function verifyEncodingFor( $server, $input, $expectations ) {
33 $expected = $this->extractExpect( $server, $expectations );
34
35 // save up global
36 $old = $_SERVER['SERVER_SOFTWARE'] ?? null;
37 $_SERVER['SERVER_SOFTWARE'] = $server;
38 wfUrlencode( null );
39
40 // do the requested test
41 $this->assertEquals(
42 $expected,
44 "Encoding '$input' for server '$server' should be '$expected'"
45 );
46
47 // restore global
48 if ( $old === null ) {
49 unset( $_SERVER['SERVER_SOFTWARE'] );
50 } else {
51 $_SERVER['SERVER_SOFTWARE'] = $old;
52 }
53 wfUrlencode( null );
54 }
55
60 private function extractExpect( $server, $expectations ) {
61 if ( is_string( $expectations ) ) {
62 return $expectations;
63 } elseif ( is_array( $expectations ) ) {
64 if ( !array_key_exists( $server, $expectations ) ) {
65 throw new MWException( __METHOD__ . " expectation does not have any "
66 . "value for server name $server. Check the provider array.\n" );
67 } else {
68 return $expectations[$server];
69 }
70 } else {
71 throw new MWException( __METHOD__ . " given invalid expectation for "
72 . "'$server'. Should be a string or an array( <http server name> => <string> ).\n" );
73 }
74 }
75
76 # ### PROVIDERS ###########################################################
77
89 public static function provideURLS() {
90 return [
91 # ## RFC 1738 chars
92 // + is not safe
93 [ '+', '%2B' ],
94 // & and = not safe in queries
95 [ '&', '%26' ],
96 [ '=', '%3D' ],
97
98 [ ':', [
99 'Apache' => ':',
100 'Microsoft-IIS/7' => '%3A',
101 ] ],
102
103 // remaining chars do not need encoding
104 [
105 ';@$-_.!*',
106 ';@$-_.!*',
107 ],
108
109 # ## Other tests
110 // slash remain unchanged. %2F seems to break things
111 [ '/', '/' ],
112 // T105265
113 [ '~', '~' ],
114
115 // Other 'funnies' chars
116 [ '[]', '%5B%5D' ],
117 [ '<>', '%3C%3E' ],
118
119 // Apostrophe is encoded
120 [ '\'', '%27' ],
121 ];
122 }
123}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
MediaWiki exception.
The function only need a string parameter and might react to IIS7.0.
testEncodingUrlWith( $input, $expected)
provideURLS
extractExpect( $server, $expectations)
Interprets the provider array.
verifyEncodingFor( $server, $input, $expectations)
Internal helper that actually run the test.
testEncodingUrlWithMicrosoftIis7( $input, $expected)
provideURLS
static provideURLS()
Format is either: [ 'input', 'expected' ]; Or: [ 'input', [ 'Apache', 'expected' ],...
if(is_array($mode)) switch( $mode) $input