Skip to content

Commit 964e420

Browse files
committed
Fix #579. Fix Nested sub path parsing in buildWithBaseURLPath. Fix tests.
1 parent 91c1a3b commit 964e420

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Saml2/Utils.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,10 @@ protected static function buildWithBaseURLPath($info)
722722
if (!empty($baseURLPath)) {
723723
$result = $baseURLPath;
724724
if (!empty($info)) {
725-
$path = explode('/', $info);
726-
$extractedInfo = array_pop($path);
725+
// Remove base path from the path info.
726+
$extractedInfo = str_replace($baseURLPath, '', $info);
727+
// Remove starting and ending slash.
728+
$extractedInfo = trim($extractedInfo, '/');
727729
if (!empty($extractedInfo)) {
728730
$result .= $extractedInfo;
729731
}

tests/src/OneLogin/Saml2/UtilsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ public function testSetBaseURL()
503503
$this->assertEquals($expectedUrl, Utils::getSelfURL());
504504

505505
Utils::setBaseURL("http://anothersp.example.com:81/example2/");
506-
$expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php';
507-
$expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php';
508-
$expectedUrl2 = 'http://anothersp.example.com:81/example2/route.php?x=test';
506+
$expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php';
507+
$expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php';
508+
$expectedUrl2 = 'http://anothersp.example.com:81/example2/example1/route.php?x=test';
509509

510510
$this->assertEquals('http', Utils::getSelfProtocol());
511511
$this->assertEquals('anothersp.example.com', Utils::getSelfHost());
@@ -517,7 +517,7 @@ public function testSetBaseURL()
517517
$this->assertEquals($expectedUrl2, Utils::getSelfURL());
518518

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

522522
$this->assertEquals($expectedUrlNQ2, Utils::getSelfURLNoQuery());
523523
$this->assertEquals($expectedRoutedUrlNQ2, Utils::getSelfRoutedURLNoQuery());

0 commit comments

Comments
 (0)