]> BookStack Code Mirror - bookstack/commitdiff
Fixed double path slash URL issue in some cases
authorDan Brown <redacted>
Wed, 4 May 2022 19:08:22 +0000 (20:08 +0100)
committerDan Brown <redacted>
Wed, 4 May 2022 19:08:22 +0000 (20:08 +0100)
- Occurred on system request path usage (Primarily on guest login
  redirection) when a custom path was not in use.
- Added test to cover.

For #3404

app/Http/Request.php
tests/UrlTest.php

index 13892603db8768df2f1bcfa012d88bc827e75959..fa368f3bca96fa829095c75a12a11dae8c42b8e4 100644 (file)
@@ -35,7 +35,8 @@ class Request extends LaravelRequest
         $appUrl = config('app.url', null);
 
         if ($appUrl) {
-            return '/' . rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
+            $parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
+            return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
         }
 
         return parent::getBaseUrl();
index 90215d558e02799bc75af878469cb79d7abe7b77..2313e02f43022f8d01fba32fbdd4d62aa29f9803 100644 (file)
@@ -34,4 +34,19 @@ class UrlTest extends TestCase
         $this->assertEquals('/cool/docs', $bsRequest->getBaseUrl());
         $this->assertEquals('https://donkey.example.com:8091/cool/docs/login', $bsRequest->getUri());
     }
+
+    public function test_app_url_without_path_does_not_duplicate_path_slash()
+    {
+        config()->set('app.url', 'https://donkey.example.com');
+
+        // Have to manually get and wrap request in our custom type due to testing mechanics
+        $this->get('/settings');
+        $bsRequest = Request::createFrom(request());
+
+        $this->assertEquals('https://donkey.example.com', $bsRequest->getSchemeAndHttpHost());
+        $this->assertEquals('', $bsRequest->getBaseUrl());
+        $this->assertEquals('/settings', $bsRequest->getPathInfo());
+        $this->assertEquals('https://donkey.example.com/settings', $bsRequest->getUri());
+    }
+
 }