Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* fixed handling of URLs with more than a domain-name (fixed opposite…

… of parse_url())

git-svn-id: http://svn.php.net/repository/pear/packages/Net_IDNA2/trunk@305340 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 81c62f2696b0efb6c5eedeb68562b99c7864019d 1 parent 95cf2e7
@neufeind neufeind authored
Showing with 38 additions and 4 deletions.
  1. +35 −1 Net/IDNA2.php
  2. +3 −3 tests/Net_IDNA2Test.php
View
36 Net/IDNA2.php
@@ -2452,7 +2452,7 @@ public function decode($input, $one_time_encoding = false)
if (isset($parsed['scheme'])) {
$parsed['scheme'] .= (strtolower($parsed['scheme']) == 'mailto') ? ':' : '://';
}
- $return = join('', $parsed);
+ $return = $this->_unparse_url($parsed);
} else { // parse_url seems to have failed, try without it
$arr = explode('.', $input);
foreach ($arr as $k => $v) {
@@ -2484,6 +2484,40 @@ public function decode($input, $one_time_encoding = false)
// {{{ private
/**
+ * Opposite function to parse_url()
+ *
+ * Inspired by code from comments of php.net-documentation for parse_url()
+ *
+ * @array string parts as returned by parse_url()
+ * @return string
+ * @access private
+ */
+ private function _unparse_url($parts_arr) {
+ if (!empty($parts_arr['scheme'])) {
+ $ret_url = $parts_arr['scheme'];
+ }
+ if(!empty($parts_arr['user'])) {
+ $ret_url .= $parts_arr['user'];
+ if (!empty($parts_arr['pass'])) {
+ $ret_url .= ':' . $parts_arr['pass'];
+ }
+ $ret_url .= '@';
+ }
+ $ret_url .= $parts_arr['host'];
+ if (!empty($parts_arr['port'])) {
+ $ret_url .= ':' . $parts_arr['port'];
+ }
+ $ret_url .= $parts_arr['path'];
+ if (!empty($parts_arr['query'])) {
+ $ret_url .= '?' . $parts_arr['query'];
+ }
+ if (!empty($parts_arr['fragment'])) {
+ $ret_url .= '#' . $parts_arr['fragment'];
+ }
+ return $ret_url;
+ }
+
+ /**
* The actual encoding algorithm.
*
* @return string
View
6 tests/Net_IDNA2Test.php
@@ -9,11 +9,11 @@ public function setUp() {
}
public function testShouldDecodePortNumbersFragmentsAndUrisCorrectly() {
- $result = $this->idn->decode('http://www.xn--ml-6kctd8d6a.org:8080/test.php?arg=1#fragment');
-
// not sure where this testcase came from, but it's wrong
+// $result = $this->idn->decode('http://www.xn--ml-6kctd8d6a.org:8080/test.php?arg1=1&arg2=2#fragment');
// $this->assertSame("http://www.ехаmрlе.org:8080/test.php?arg=1#fragment", $result);
- $this->assertSame("http://www.example.org:8080/test.php?arg=1#fragment", $result);
+ $result = $this->idn->decode('http://xn--tst-qla.example.com:8080/test.php?arg1=1&arg2=2#fragment');
+ $this->assertSame("http://täst.example.com:8080/test.php?arg1=1&arg2=2#fragment", $result);
}
public function testEncodingForGermanEszettUsingIDNA2003() {
Please sign in to comment.
Something went wrong with that request. Please try again.