NOW MANAGED ON CODEBERG
Fixed redirect issue when custom app url in use
Dan Brown19b709343845
diff --git a/app/helpers.php b/app/helpers.phpindex 50b41ec05..4c0521d3a 100644--- a/app/helpers.php+++ b/app/helpers.php@@ -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 domainif ($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;}/**diff --git a/phpunit.xml b/phpunit.xmlindex 4c1e4f66c..efed0070e 100644--- a/phpunit.xml+++ b/phpunit.xml@@ -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.phpnew file mode 100644index 000000000..30b0085d6--- /dev/null+++ b/tests/HelpersTest.php@@ -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