From: Dan Brown Date: Sun, 1 Sep 2019 11:07:51 +0000 (+0100) Subject: Fixed URL gen issue causing incorrect scheme to be used X-Git-Tag: v0.27.2~1^2 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/7a4425473b61007f6eee51a3f794f5908cd2ccd8 Fixed URL gen issue causing incorrect scheme to be used For #1613 --- diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a2fc673f4..b46a716cc 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -25,7 +25,12 @@ class AppServiceProvider extends ServiceProvider public function boot() { // Set root URL - URL::forceRootUrl(config('app.url')); + $appUrl = config('app.url'); + if ($appUrl) { + $isHttps = (strpos($appUrl, 'https://') === 0); + URL::forceRootUrl($appUrl); + URL::forceScheme($isHttps ? 'https' : 'http'); + } // Custom validation methods Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) { diff --git a/tests/Unit/UrlTest.php b/tests/Unit/UrlTest.php index c7d33312c..1667f5f7b 100644 --- a/tests/Unit/UrlTest.php +++ b/tests/Unit/UrlTest.php @@ -22,4 +22,12 @@ class UrlTest extends TestCase putenv('APP_URL='); } + public function test_url_helper_sets_correct_scheme_even_when_request_scheme_is_different() + { + putenv('APP_URL=https://example.com/'); + $this->refreshApplication(); + $this->get('http://example.com/login')->assertSee('https://example.com/dist/styles.css'); + putenv('APP_URL='); + } + } \ No newline at end of file