Skip to content

Commit

Permalink
Merge pull request #128 from ozh/hashproblem
Browse files Browse the repository at this point in the history
Fix IRI "normalization"
  • Loading branch information
rmccue committed Nov 30, 2014
2 parents b398534 + aca2b1e commit 3244985
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
7 changes: 4 additions & 3 deletions library/Requests/IRI.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ class Requests_IRI
),
'http' => array(
'port' => 80,
'ipath' => '/'
),
'https' => array(
'port' => 443,
'ipath' => '/'
),
);

Expand Down Expand Up @@ -743,6 +741,10 @@ protected function scheme_normalization()
{
$this->ipath = '';
}
if (isset($this->ihost) && empty($this->ipath))
{
$this->ipath = '/';
}
if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery'])
{
$this->iquery = null;
Expand Down Expand Up @@ -1060,7 +1062,6 @@ protected function set_path($ipath)
$cache[$ipath] = array($valid, $removed);
$this->ipath = ($this->scheme !== null) ? $removed : $valid;
}

$this->scheme_normalization();
return true;
}
Expand Down
82 changes: 41 additions & 41 deletions tests/IRI.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function rfc3986_tests()
array('./g', 'http://a/b/c/g'),
array('g/', 'http://a/b/c/g/'),
array('/g', 'http://a/g'),
array('//g', 'http://g'),
array('//g', 'http://g/'),
array('?y', 'http://a/b/c/d;p?y'),
array('g?y', 'http://a/b/c/g?y'),
array('#s', 'http://a/b/c/d;p?q#s'),
Expand All @@ -66,8 +66,8 @@ public static function rfc3986_tests()
array('..', 'http://a/b/'),
array('../', 'http://a/b/'),
array('../g', 'http://a/b/g'),
array('../..', 'http://a'),
array('../../', 'http://a'),
array('../..', 'http://a/'),
array('../../', 'http://a/'),
array('../../g', 'http://a/g'),
// Abnormal
array('../../../g', 'http://a/g'),
Expand Down Expand Up @@ -132,14 +132,14 @@ public static function sp_tests()
array('http://a/b', 'c', 'http://a/c'),
array('http://a/b/', "c\x0Ad", 'http://a/b/c%0Ad'),
array('http://a/b/', "c\x0A\x0B", 'http://a/b/c%0A%0B'),
array('http://a/b/c', '//0', 'http://0'),
array('http://a/b/c', '//0', 'http://0/'),
array('http://a/b/c', '0', 'http://a/b/0'),
array('http://a/b/c', '?0', 'http://a/b/c?0'),
array('http://a/b/c', '#0', 'http://a/b/c#0'),
array('http://0/b/c', 'd', 'http://0/b/d'),
array('http://a/b/c?0', 'd', 'http://a/b/d'),
array('http://a/b/c#0', 'd', 'http://a/b/d'),
array('http://example.com', '//example.net', 'http://example.net'),
array('http://example.com', '//example.net', 'http://example.net/'),
array('http:g', 'a', 'http:a'),
);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public static function absolutize_tests()
{
return array(
array('http://example.com/', 'foo/111:bar', 'http://example.com/foo/111:bar'),
array('http://example.com/#foo', '', 'http://example.com'),
array('http://example.com/#foo', '', 'http://example.com/'),
);
}

Expand Down Expand Up @@ -201,38 +201,38 @@ public static function normalization_tests()
array('example://A/', 'example://a/'),
array('example://a/', 'example://a/'),
array('example://%25A/', 'example://%25a/'),
array('HTTP://EXAMPLE.com/', 'http://example.com'),
array('http://example.com/', 'http://example.com'),
array('http://example.com:', 'http://example.com'),
array('http://example.com:80', 'http://example.com'),
array('http://@example.com', 'http://@example.com'),
array('http://', 'http://'),
array('http://example.com?', 'http://example.com?'),
array('http://example.com#', 'http://example.com#'),
array('https://example.com/', 'https://example.com'),
array('https://example.com:', 'https://example.com'),
array('https://@example.com', 'https://@example.com'),
array('https://example.com?', 'https://example.com?'),
array('https://example.com#', 'https://example.com#'),
array('HTTP://EXAMPLE.com/', 'http://example.com/'),
array('http://example.com/', 'http://example.com/'),
array('http://example.com:', 'http://example.com/'),
array('http://example.com:80', 'http://example.com/'),
array('http://@example.com', 'http://@example.com/'),
array('http://', 'http:///'),
array('http://example.com?', 'http://example.com/?'),
array('http://example.com#', 'http://example.com/#'),
array('https://example.com/', 'https://example.com/'),
array('https://example.com:', 'https://example.com/'),
array('https://@example.com', 'https://@example.com/'),
array('https://example.com?', 'https://example.com/?'),
array('https://example.com#', 'https://example.com/#'),
array('file://localhost/foobar', 'file:/foobar'),
array('http://[0:0:0:0:0:0:0:1]', 'http://[::1]'),
array('http://[2001:db8:85a3:0000:0000:8a2e:370:7334]', 'http://[2001:db8:85a3::8a2e:370:7334]'),
array('http://[0:0:0:0:0:ffff:c0a8:a01]', 'http://[::ffff:c0a8:a01]'),
array('http://[ffff:0:0:0:0:0:0:0]', 'http://[ffff::]'),
array('http://[::ffff:192.0.2.128]', 'http://[::ffff:192.0.2.128]'),
array('http://[0:0:0:0:0:0:0:1]', 'http://[::1]/'),
array('http://[2001:db8:85a3:0000:0000:8a2e:370:7334]', 'http://[2001:db8:85a3::8a2e:370:7334]/'),
array('http://[0:0:0:0:0:ffff:c0a8:a01]', 'http://[::ffff:c0a8:a01]/'),
array('http://[ffff:0:0:0:0:0:0:0]', 'http://[ffff::]/'),
array('http://[::ffff:192.0.2.128]', 'http://[::ffff:192.0.2.128]/'),
array('http://[invalid]', 'http:'),
array('http://[0:0:0:0:0:0:0:1]:', 'http://[::1]'),
array('http://[0:0:0:0:0:0:0:1]:80', 'http://[::1]'),
array('http://[0:0:0:0:0:0:0:1]:1234', 'http://[::1]:1234'),
array('http://[0:0:0:0:0:0:0:1]:', 'http://[::1]/'),
array('http://[0:0:0:0:0:0:0:1]:80', 'http://[::1]/'),
array('http://[0:0:0:0:0:0:0:1]:1234', 'http://[::1]:1234/'),
// Punycode decoding helps with normalisation of IRIs, but is not
// needed for URIs, so we don't really care about it for Requests
//array('http://xn--tdali-d8a8w.lv', 'http://tūdaliņ.lv'),
//array('http://t%C5%ABdali%C5%86.lv', 'http://tūdaliņ.lv'),
array('http://[email protected]', 'http://[email protected]'),
array('http://example.com?Aa', 'http://example.com?Aa'),
//array('http://xn--tdali-d8a8w.lv', 'http://tūdaliņ.lv/'),
//array('http://t%C5%ABdali%C5%86.lv', 'http://tūdaliņ.lv/'),
array('http://[email protected]', 'http://[email protected]/'),
array('http://example.com?Aa', 'http://example.com/?Aa'),
array('http://example.com/Aa', 'http://example.com/Aa'),
array('http://example.com#Aa', 'http://example.com#Aa'),
array('http://[0:0:0:0:0:0:0:0]', 'http://[::]'),
array('http://example.com#Aa', 'http://example.com/#Aa'),
array('http://[0:0:0:0:0:0:0:0]', 'http://[::]/'),
array('http:.', 'http:'),
array('http:..', 'http:'),
array('http:./', 'http:'),
Expand All @@ -249,15 +249,15 @@ public static function normalization_tests()
array("http://example.com/\xF3\xB0\x80\x80", 'http://example.com/%F3%B0%80%80'),
array("http://example.com/\xF3\xB0\x80\x80%00", 'http://example.com/%F3%B0%80%80%00'),
array("http://example.com/\xF3\xB0\x80\x80a", 'http://example.com/%F3%B0%80%80a'),
array("http://example.com?\xF3\xB0\x80\x80", "http://example.com?\xF3\xB0\x80\x80"),
array("http://example.com?\xF3\xB0\x80\x80%00", "http://example.com?\xF3\xB0\x80\x80%00"),
array("http://example.com?\xF3\xB0\x80\x80a", "http://example.com?\xF3\xB0\x80\x80a"),
array("http://example.com?\xF3\xB0\x80\x80", "http://example.com/?\xF3\xB0\x80\x80"),
array("http://example.com?\xF3\xB0\x80\x80%00", "http://example.com/?\xF3\xB0\x80\x80%00"),
array("http://example.com?\xF3\xB0\x80\x80a", "http://example.com/?\xF3\xB0\x80\x80a"),
array("http://example.com/\xEE\x80\x80", 'http://example.com/%EE%80%80'),
array("http://example.com/\xEE\x80\x80%00", 'http://example.com/%EE%80%80%00'),
array("http://example.com/\xEE\x80\x80a", 'http://example.com/%EE%80%80a'),
array("http://example.com?\xEE\x80\x80", "http://example.com?\xEE\x80\x80"),
array("http://example.com?\xEE\x80\x80%00", "http://example.com?\xEE\x80\x80%00"),
array("http://example.com?\xEE\x80\x80a", "http://example.com?\xEE\x80\x80a"),
array("http://example.com?\xEE\x80\x80", "http://example.com/?\xEE\x80\x80"),
array("http://example.com?\xEE\x80\x80%00", "http://example.com/?\xEE\x80\x80%00"),
array("http://example.com?\xEE\x80\x80a", "http://example.com/?\xEE\x80\x80a"),
array("http://example.com/\xC2", 'http://example.com/%C2'),
array("http://example.com/\xC2a", 'http://example.com/%C2a'),
array("http://example.com/\xC2\x00", 'http://example.com/%C2%00'),
Expand All @@ -268,8 +268,8 @@ public static function normalization_tests()
array("http://example.com/\xFF%00", 'http://example.com/%FF%00'),
array("http://example.com/\xFFa", 'http://example.com/%FFa'),
array('http://example.com/%61', 'http://example.com/a'),
array('http://example.com?%26', 'http://example.com?%26'),
array('http://example.com?%61', 'http://example.com?a'),
array('http://example.com?%26', 'http://example.com/?%26'),
array('http://example.com?%61', 'http://example.com/?a'),
array('///', '///'),
);
}
Expand Down

0 comments on commit 3244985

Please sign in to comment.