diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index 06f4e0b37d15420febdee49f6949a746a96a6db1..7233c9cc19841f6c381976d7a852565503c3eaf6 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -110,6 +110,9 @@ class HTTP { $default_port = self::getServerHTTPS() ? '443' : '80'; $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : $default_port; + + // Take care of edge-case where SERVER_PORT is an integer + $port = strval($port); if ($port !== $default_port) { return ':'.$port; diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php index 2abf7e9d406c22e758d2c0eeebac2fd9ad9b88ea..d5708322bc32d9affcea91fc9e1541309c2504f0 100644 --- a/tests/lib/SimpleSAML/Utils/HTTPTest.php +++ b/tests/lib/SimpleSAML/Utils/HTTPTest.php @@ -366,6 +366,10 @@ class HTTPTest extends TestCase $_SERVER['SERVER_PORT'] = '80'; $this->assertEquals(HTTP::getServerPort(), ''); + // Test HTTP + standard integer port + $_SERVER['SERVER_PORT'] = 80; + $this->assertEquals(HTTP::getServerPort(), ''); + // Test HTTP + without port unset($_SERVER['SERVER_PORT']); $this->assertEquals(HTTP::getServerPort(), ''); @@ -375,6 +379,10 @@ class HTTPTest extends TestCase $_SERVER['SERVER_PORT'] = '3030'; $this->assertEquals(HTTP::getServerPort(), ':3030'); + // Test HTTPS + non-standard integer port + $_SERVER['SERVER_PORT'] = 3030; + $this->assertEquals(HTTP::getServerPort(), ':3030'); + // Test HTTPS + standard port $_SERVER['SERVER_PORT'] = '443'; $this->assertEquals(HTTP::getServerPort(), '');