File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed
Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 11ChangeLog
22=========
33
4+ 1.1.0 (2016-03-07)
5+ ------------------
6+
7+ * #6 : PHP's ` parse_url() ` corrupts strings if they contain certain
8+ non ascii-characters such as Chinese or Hebrew. sabre/uri's ` parse() `
9+ function now percent-encodes these characters beforehand.
10+
11+
4121.0.1 (2015-04-28)
513------------------
614
Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ class Version {
1414 /**
1515 * Full version number
1616 */
17- const VERSION = '1.0.1 ' ;
17+ const VERSION = '1.1.0 ' ;
1818
1919}
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ function resolve($basePath, $newPath) {
3333 return $ base [$ part ];
3434 }
3535 return null ;
36-
36+
3737 };
3838
3939 // If the new path defines a scheme, it's absolute and we can just return
@@ -172,11 +172,29 @@ function normalize($uri) {
172172 * return an array with all the array keys, including the ones that are not
173173 * set by parse_url, which makes it a bit easier to work with.
174174 *
175+ * Unlike PHP's parse_url, it will also convert any non-ascii characters to
176+ * percent-encoded strings. PHP's parse_url corrupts these characters on OS X.
177+ *
175178 * @param string $uri
176179 * @return array
177180 */
178181function parse ($ uri ) {
179182
183+ // Normally a URI must be ASCII, however. However, often it's not and
184+ // parse_url might corrupt these strings.
185+ //
186+ // For that reason we take any non-ascii characters from the uri and
187+ // uriencode them first.
188+ $ uri = preg_replace_callback (
189+ '/[^[:ascii:]]/u ' ,
190+ function ($ matches ) {
191+ return rawurlencode ($ matches [0 ]);
192+ },
193+ $ uri
194+ );
195+
196+ if ($ uri !==$ uri ) die ($ uri . "\n" );
197+
180198 return
181199 parse_url ($ uri ) + [
182200 'scheme ' => null ,
@@ -262,5 +280,5 @@ function split($path) {
262280 return [$ matches [1 ], $ matches [2 ]];
263281 }
264282 return [null ,null ];
265-
283+
266284}
Original file line number Diff line number Diff line change @@ -38,8 +38,7 @@ function parseData() {
3838 [
3939 'scheme ' => 'http ' ,
4040 'host ' => 'example.org ' ,
41- //'path' => '/%E6%9C%89%E8%AF%8D%E6%B3%95%E5%88%AB%E5%90%8D.zh',
42- 'path ' => '/%有词法别名.zh ' ,
41+ 'path ' => '/%E6%9C%89%E8%AF%8D%E6%B3%95%E5%88%AB%E5%90%8D.zh ' ,
4342 'port ' => null ,
4443 'user ' => null ,
4544 'query ' => null ,
You can’t perform that action at this time.
0 commit comments