From 772a655e6b114b163ff12ff9f1e590975660e9db Mon Sep 17 00:00:00 2001 From: Sixto Martin Date: Sun, 29 Sep 2024 18:28:47 +0200 Subject: [PATCH] See #581. buildWithBaseURLPath returned only last part of url --- lib/Saml2/Utils.php | 6 ++++-- tests/src/OneLogin/Saml2/UtilsTest.php | 14 ++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Saml2/Utils.php b/lib/Saml2/Utils.php index c0e35346..521cb3f0 100644 --- a/lib/Saml2/Utils.php +++ b/lib/Saml2/Utils.php @@ -709,8 +709,10 @@ protected static function buildWithBaseURLPath($info) if (!empty($baseURLPath)) { $result = $baseURLPath; if (!empty($info)) { - $path = explode('/', $info); - $extractedInfo = array_pop($path); + // Remove base path from the path info. + $extractedInfo = str_replace($baseURLPath, '', $info); + // Remove starting and ending slash. + $extractedInfo = trim($extractedInfo, '/'); if (!empty($extractedInfo)) { $result .= $extractedInfo; } diff --git a/tests/src/OneLogin/Saml2/UtilsTest.php b/tests/src/OneLogin/Saml2/UtilsTest.php index 0bbe7690..c09335eb 100644 --- a/tests/src/OneLogin/Saml2/UtilsTest.php +++ b/tests/src/OneLogin/Saml2/UtilsTest.php @@ -488,9 +488,9 @@ public function testSetBaseURL() $this->assertEquals($expectedUrl, OneLogin_Saml2_Utils::getSelfURL()); OneLogin_Saml2_Utils::setBaseURL("http://anothersp.example.com:81/example2/"); - $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php'; - $expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php'; - $expectedUrl2 = 'http://anothersp.example.com:81/example2/route.php?x=test'; + $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php'; + $expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php'; + $expectedUrl2 = 'http://anothersp.example.com:81/example2/example1/route.php?x=test'; $this->assertEquals('http', OneLogin_Saml2_Utils::getSelfProtocol()); $this->assertEquals('anothersp.example.com', OneLogin_Saml2_Utils::getSelfHost()); @@ -502,11 +502,17 @@ public function testSetBaseURL() $this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL()); $_SERVER['PATH_INFO'] = '/test'; - $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php/test'; + $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php/test'; $this->assertEquals($expectedUrlNQ2, OneLogin_Saml2_Utils::getSelfURLNoQuery()); $this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery()); $this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL()); + + OneLogin_Saml2_Utils::setBaseURL("http://anothersp.example.com:81/example2"); + $this->assertEquals($expectedUrlNQ2, OneLogin_Saml2_Utils::getSelfURLNoQuery()); + $this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery()); + $this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL()); + $this->assertEquals('/example2/', OneLogin_Saml2_Utils::getBaseURLPath()); } /**