]> BookStack Code Mirror - bookstack/commitdiff
Fixed redirect issue when custom app url in use
authorDan Brown <redacted>
Sun, 4 Nov 2018 15:18:27 +0000 (15:18 +0000)
committerDan Brown <redacted>
Sun, 4 Nov 2018 15:18:27 +0000 (15:18 +0000)
Fixes #956 & #1048
Also added tests to cover this url logic.
Also removed debugbar during tests to maybe improve test speed.

app/helpers.php
phpunit.xml
tests/HelpersTest.php [new file with mode: 0644]

index 50b41ec05d9180ad1a2ebf8d60b3e7867f793bc2..4c0521d3a0c65c71785dc065ef834ec3956e631b 100644 (file)
@@ -92,10 +92,15 @@ function baseUrl($path, $forceAppDomain = false)
     if ($isFullUrl && !$forceAppDomain) {
         return $path;
     }
+
     $path = trim($path, '/');
+    $trimBase = rtrim(config('app.url'), '/');
 
     // Remove non-specified domain if forced and we have a domain
     if ($isFullUrl && $forceAppDomain) {
+        if (strpos($path, $trimBase) === 0) {
+            $path = trim(substr($path, strlen($trimBase) - 1));
+        }
         $explodedPath = explode('/', $path);
         $path = implode('/', array_splice($explodedPath, 3));
     }
@@ -105,7 +110,7 @@ function baseUrl($path, $forceAppDomain = false)
         return url($path);
     }
 
-    return rtrim(config('app.url'), '/') . '/' . $path;
+    return $trimBase . '/' . $path;
 }
 
 /**
index 4c1e4f66c9fd5e8b30365d9b3734a0ca1ce785c0..efed0070e234674fb793d03403f279e60d27caa6 100644 (file)
@@ -42,5 +42,6 @@
         <env name="GOOGLE_AUTO_REGISTER" value=""/>
         <env name="GOOGLE_AUTO_CONFIRM_EMAIL" value=""/>
         <env name="APP_URL" value="http://bookstack.dev"/>
+        <env name="DEBUGBAR_ENABLED" value="false"/>
     </php>
 </phpunit>
diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php
new file mode 100644 (file)
index 0000000..30b0085
--- /dev/null
@@ -0,0 +1,19 @@
+<?php namespace Tests;
+
+class HelpersTest extends TestCase
+{
+
+    public function test_base_url_takes_config_into_account()
+    {
+        config()->set('app.url', 'http://example.com/bookstack');
+        $result = baseUrl('/');
+        $this->assertEquals('http://example.com/bookstack/', $result);
+    }
+
+    public function test_base_url_takes_extra_path_into_account_on_forced_domain()
+    {
+        config()->set('app.url', 'http://example.com/bookstack');
+        $result = baseUrl('http://example.com/bookstack/', true);
+        $this->assertEquals('http://example.com/bookstack/', $result);
+    }
+}
\ No newline at end of file