diff --git a/VERSIONS b/VERSIONS index 51d52a946cf7dd912932e64f47f12b92aeb8c2b6..112b15d963745a00b994fc45f303f9242302cf90 100644 --- a/VERSIONS +++ b/VERSIONS @@ -1,3 +1,7 @@ + + - ticket #57929 : Liens permanents : sur un accès en https, Bokeh n'ajoute plus le port par défaut (:443) + + 18/05/2017 - v7.9.19 - ticket #60547 : Cosmogramme : correction d'erreurs dans les écrans de configuration des intégrations, d'analyse de fichier unimarc et de modifications des codifications Dewey et PCDM4 diff --git a/library/Class/Url.php b/library/Class/Url.php index 4d781f055987b6406506dcdee4718c7a1615d805..7344b9041fcfacb47e3bb1a491a986d28237ad3c 100644 --- a/library/Class/Url.php +++ b/library/Class/Url.php @@ -113,6 +113,9 @@ class Class_Url { public static function getPort() { $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80; + if (static::isSecure() && 443 == $port) + return ''; + return $port == 80 ? '' : ':' . $port; } diff --git a/tests/library/Class/UrlTest.php b/tests/library/Class/UrlTest.php index 863b6387bd184b6f278be731b674f5ed800043bb..f4669df3615680fc1186724785e15b21506767c3 100644 --- a/tests/library/Class/UrlTest.php +++ b/tests/library/Class/UrlTest.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class UrlBaseUrlTest extends ModelTestCase { +abstract class UrlTestCase extends ModelTestCase { protected $_storm_default_to_volatile = true, $_server_backup; @@ -31,12 +31,16 @@ class UrlBaseUrlTest extends ModelTestCase { $this->_server_backup = $_SERVER; } + public function tearDown() { $_SERVER = $this->_server_backup; parent::tearDown(); } +} + +class UrlBaseUrlTest extends UrlTestCase { /** @test */ public function bokehInstalledInASubdirectory() { $_SERVER['SCRIPT_NAME'] = '/home/tom/public_html/bokeh/index.php'; @@ -63,8 +67,39 @@ class UrlBaseUrlTest extends ModelTestCase { /** @test */ public function absoluteUrlShouldReturnCorrectSyntax() { - $this->assertContains('http://' . $_SERVER['SERVER_NAME'] . '/', Class_Url::absolute(['module' => 'admin', - 'controller' => 'cms', - 'action' => 'index'])); + $this->assertContains('http://' . $_SERVER['SERVER_NAME'] . '/', + Class_Url::absolute(['module' => 'admin', + 'controller' => 'cms', + 'action' => 'index'])); + } +} + + + +/** @see http://forge.afi-sa.fr/issues/57929 */ +class UrlHttpsTest extends UrlTestCase { + public function setUp() { + parent::setUp(); + $_SERVER['HTTPS'] = 'on'; + } + + + /** @test */ + public function absoluteUrlShouldNotRepeatDefaultPort() { + $_SERVER['SERVER_PORT'] = '443'; + $this->assertNotContains(':443', + Class_Url::absolute(['module' => 'opac', + 'controller' => 'recherche', + 'action' => 'viewnotice'])); + } + + + /** @test */ + public function absoluteUrlShouldInsertExoticPort() { + $_SERVER['SERVER_PORT'] = '4433'; + $this->assertContains(':4433', + Class_Url::absolute(['module' => 'opac', + 'controller' => 'recherche', + 'action' => 'viewnotice'])); } }