Permalink
Browse files

Merge branch 'hotfix/3167' into develop

Forward port #3167
  • Loading branch information...
2 parents 5c27e8e + efc545e commit 2888753439b85c7475d6e0556e39259977695235 @weierophinney weierophinney committed Dec 11, 2012
Showing with 18 additions and 0 deletions.
  1. +9 −0 library/Zend/View/Helper/ServerUrl.php
  2. +9 −0 tests/ZendTest/View/Helper/ServerUrlTest.php
@@ -180,6 +180,15 @@ protected function detectHost()
}
if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
+ // Detect if the port is set in SERVER_PORT and included in HTTP_HOST
+ if (isset($_SERVER['SERVER_PORT'])) {
+ $portStr = ':' . $_SERVER['SERVER_PORT'];
+ if (substr($_SERVER['HTTP_HOST'], 0-strlen($portStr), strlen($portStr)) == $portStr) {
+ $this->setHost(substr($_SERVER['HTTP_HOST'], 0, 0-strlen($portStr)));
+ return;
+ }
+ }
+
$this->setHost($_SERVER['HTTP_HOST']);
return;
}
@@ -91,6 +91,15 @@ public function testConstructorWithHostIncludingPortAndHttpsTrue()
$this->assertEquals('https://example.com:8181', $url->__invoke());
}
+ public function testConstructorWithHttpHostIncludingPortAndPortSet()
+ {
+ $_SERVER['HTTP_HOST'] = 'example.com:8181';
+ $_SERVER['SERVER_PORT'] = 8181;
+
+ $url = new Helper\ServerUrl();
+ $this->assertEquals('http://example.com:8181', $url->__invoke());
+ }
+
public function testConstructorWithHttpHostAndServerNameAndPortSet()
{
$_SERVER['HTTP_HOST'] = 'example.com';

0 comments on commit 2888753

Please sign in to comment.