From 892784a8f335e5061207358208cba701a739ac94 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Tue, 7 Jun 2016 14:58:01 +0200
Subject: [PATCH] Be graceful with the 'baseurlpath' configuration option. We
 should not fail when the trailing slash is missing, just add it.

---
 lib/SimpleSAML/Configuration.php | 8 ++++++--
 lib/SimpleSAML/Utils/HTTP.php    | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index fb2108d46..b477c8a85 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -454,9 +454,13 @@ class SimpleSAML_Configuration
             return \SimpleSAML\Utils\HTTP::getFirstPathElement(false).$matches[1];
         }
 
-        if (preg_match('#^https?://[^/]*/(.*)$#', $baseURL, $matches)) {
+        if (preg_match('#^https?://[^/]*(?:/(.+/?)?)?$#', $baseURL, $matches)) {
             // we have a full url, we need to strip the path
-            return $matches[1];
+            if (!array_key_exists(1, $matches)) {
+                // root directory specified with an absolute URL
+                return '';
+            }
+            return rtrim($matches[1], '/')."/";
         } elseif ($baseURL === '' || $baseURL === '/') {
             // Root directory of site
             return '';
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index 2251eee59..d802370dc 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -566,9 +566,9 @@ class HTTP
         $globalConfig = \SimpleSAML_Configuration::getInstance();
         $baseURL = $globalConfig->getString('baseurlpath', 'simplesaml/');
 
-        if (preg_match('#^https?://.*/$#D', $baseURL, $matches)) {
+        if (preg_match('#^https?://.*/?$#D', $baseURL, $matches)) {
             // full URL in baseurlpath, override local server values
-            return $baseURL;
+            return rtrim($baseURL, '/').'/';
         } elseif (
             (preg_match('#^/?([^/]?.*/)$#D', $baseURL, $matches)) ||
             (preg_match('#^\*(.*)/$#D', $baseURL, $matches)) ||
-- 
GitLab