]> BookStack Code Mirror - bookstack/commitdiff
Fixed faulty baseUrl rewrites
authorDan Brown <redacted>
Sun, 19 May 2019 15:25:05 +0000 (16:25 +0100)
committerDan Brown <redacted>
Sun, 19 May 2019 15:25:05 +0000 (16:25 +0100)
Fixes #1452
May help #1377

app/helpers.php
tests/Auth/AuthTest.php
tests/Unit/HelpersTest.php

index 65b61c9f06f30b84883cf5c0475c72a04fb1c237..0fedf2e8db30a009a805635b09544d1b2e0c1e0c 100644 (file)
@@ -123,10 +123,11 @@ function baseUrl($path, $forceAppDomain = false)
     // Remove non-specified domain if forced and we have a domain
     if ($isFullUrl && $forceAppDomain) {
         if (!empty($base) && strpos($path, $base) === 0) {
-            $path = trim(substr($path, strlen($base) - 1));
+            $path = substr($path, strlen($base));
+        } else {
+            $explodedPath = explode('/', $path);
+            $path = implode('/', array_splice($explodedPath, 3));
         }
-        $explodedPath = explode('/', $path);
-        $path = implode('/', array_splice($explodedPath, 3));
     }
 
     // Return normal url path if not specified in config
@@ -134,7 +135,7 @@ function baseUrl($path, $forceAppDomain = false)
         return url($path);
     }
 
-    return $base . '/' . $path;
+    return $base . '/' . ltrim($path, '/');
 }
 
 /**
index c39ef68e56399740b3ace0965e2d3d29b67d61dc..0399f2b818e809121ea45a4cc5fa0d04087d9d87 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace Tests;
 
+use BookStack\Entities\Page;
 use BookStack\Notifications\ConfirmEmail;
 use BookStack\Auth\User;
 use BookStack\Settings\SettingService;
@@ -334,6 +335,17 @@ class AuthTest extends BrowserKitTest
             ->seeLink('Sign up');
     }
 
+    public function test_login_redirects_to_initially_requested_url_correctly()
+    {
+        config()->set('app.url', 'http://localhost');
+        $page = Page::query()->first();
+
+        $this->visit($page->getUrl())
+            ->seePageUrlIs(baseUrl('/login'));
+        $this->login('admin@admin.com', 'password')
+            ->seePageUrlIs($page->getUrl());
+    }
+
     /**
      * Perform a login
      * @param string $email
index 30b0085d6d5340c4703435f166c19ce129c70f7f..c8f4ce294d4bdbf7460539c1b677f1d6e1412d42 100644 (file)
@@ -16,4 +16,18 @@ class HelpersTest extends TestCase
         $result = baseUrl('http://example.com/bookstack/', true);
         $this->assertEquals('http://example.com/bookstack/', $result);
     }
+
+    public function test_base_url_force_domain_works_as_expected_with_full_url_given()
+    {
+        config()->set('app.url', 'http://example.com');
+        $result = baseUrl('http://examps.com/books/test/page/cat', true);
+        $this->assertEquals('http://example.com/books/test/page/cat', $result);
+    }
+
+    public function test_base_url_force_domain_works_when_app_domain_is_same_as_given_url()
+    {
+        config()->set('app.url', 'http://example.com');
+        $result = baseUrl('http://example.com/books/test/page/cat', true);
+        $this->assertEquals('http://example.com/books/test/page/cat', $result);
+    }
 }
\ No newline at end of file
Morty Proxy This is a proxified and sanitized view of the page, visit original site.