Skip to content

Commit 772a655

Browse files
committed
See #581. buildWithBaseURLPath returned only last part of url
1 parent 14af016 commit 772a655

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/Saml2/Utils.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,10 @@ protected static function buildWithBaseURLPath($info)
709709
if (!empty($baseURLPath)) {
710710
$result = $baseURLPath;
711711
if (!empty($info)) {
712-
$path = explode('/', $info);
713-
$extractedInfo = array_pop($path);
712+
// Remove base path from the path info.
713+
$extractedInfo = str_replace($baseURLPath, '', $info);
714+
// Remove starting and ending slash.
715+
$extractedInfo = trim($extractedInfo, '/');
714716
if (!empty($extractedInfo)) {
715717
$result .= $extractedInfo;
716718
}

tests/src/OneLogin/Saml2/UtilsTest.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ public function testSetBaseURL()
488488
$this->assertEquals($expectedUrl, OneLogin_Saml2_Utils::getSelfURL());
489489

490490
OneLogin_Saml2_Utils::setBaseURL("http://anothersp.example.com:81/example2/");
491-
$expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php';
492-
$expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php';
493-
$expectedUrl2 = 'http://anothersp.example.com:81/example2/route.php?x=test';
491+
$expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php';
492+
$expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php';
493+
$expectedUrl2 = 'http://anothersp.example.com:81/example2/example1/route.php?x=test';
494494

495495
$this->assertEquals('http', OneLogin_Saml2_Utils::getSelfProtocol());
496496
$this->assertEquals('anothersp.example.com', OneLogin_Saml2_Utils::getSelfHost());
@@ -502,11 +502,17 @@ public function testSetBaseURL()
502502
$this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL());
503503

504504
$_SERVER['PATH_INFO'] = '/test';
505-
$expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php/test';
505+
$expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php/test';
506506

507507
$this->assertEquals($expectedUrlNQ2, OneLogin_Saml2_Utils::getSelfURLNoQuery());
508508
$this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
509509
$this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL());
510+
511+
OneLogin_Saml2_Utils::setBaseURL("http://anothersp.example.com:81/example2");
512+
$this->assertEquals($expectedUrlNQ2, OneLogin_Saml2_Utils::getSelfURLNoQuery());
513+
$this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
514+
$this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL());
515+
$this->assertEquals('/example2/', OneLogin_Saml2_Utils::getBaseURLPath());
510516
}
511517

512518
/**

0 commit comments

Comments
 (0)