From 9f8f1e786a9c5189df3bbf025df42473f8853a92 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Wed, 18 Mar 2020 10:48:13 +0800 Subject: [PATCH] increase browser requirement --- app/Http/Kernel.php | 2 +- app/Http/Middleware/EnforceEverGreen.php | 25 +++++++++++++++++++ app/Http/Middleware/ForbiddenIE.php | 19 -------------- resources/lang/en/errors.yml | 2 +- ...denIETest.php => EnforceEverGreenTest.php} | 5 +++- 5 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 app/Http/Middleware/EnforceEverGreen.php delete mode 100644 app/Http/Middleware/ForbiddenIE.php rename tests/HttpTest/MiddlewareTest/{ForbiddenIETest.php => EnforceEverGreenTest.php} (57%) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 7a1419ac..77951be2 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -32,7 +32,7 @@ class Kernel extends HttpKernel \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class, - \App\Http\Middleware\ForbiddenIE::class, + \App\Http\Middleware\EnforceEverGreen::class, \App\Http\Middleware\RedirectToSetup::class, ], diff --git a/app/Http/Middleware/EnforceEverGreen.php b/app/Http/Middleware/EnforceEverGreen.php new file mode 100644 index 00000000..1c01ece3 --- /dev/null +++ b/app/Http/Middleware/EnforceEverGreen.php @@ -0,0 +1,25 @@ +userAgent(); + + preg_match('/Chrome\/(\d+)/', $userAgent, $matches); + $isOldChrome = Arr::has($matches, 1) && $matches[1] < 55; + + if ($isOldChrome || Str::contains($userAgent, ['Trident', 'MSIE'])) { + throw new PrettyPageException(trans('errors.http.ie')); + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/ForbiddenIE.php b/app/Http/Middleware/ForbiddenIE.php deleted file mode 100644 index 57fc2b59..00000000 --- a/app/Http/Middleware/ForbiddenIE.php +++ /dev/null @@ -1,19 +0,0 @@ -userAgent(), ['Trident', 'MSIE'])) { - throw new PrettyPageException(trans('errors.http.ie')); - } - - return $next($request); - } -} diff --git a/resources/lang/en/errors.yml b/resources/lang/en/errors.yml index 5668fb5a..299f4445 100644 --- a/resources/lang/en/errors.yml +++ b/resources/lang/en/errors.yml @@ -5,7 +5,7 @@ http: msg-503: The application is now in maintenance mode. method-not-allowed: Method not allowed. csrf-token-mismatch: Token does not match, try reloading the page. - ie: We don't support Internet Explorer. Please switch to other modern browsers, such as Firefox or Chrome. + ie: Your browser isn't supported. Please switch to other modern browsers, such as Firefox or Chrome. general: title: Error occurred diff --git a/tests/HttpTest/MiddlewareTest/ForbiddenIETest.php b/tests/HttpTest/MiddlewareTest/EnforceEverGreenTest.php similarity index 57% rename from tests/HttpTest/MiddlewareTest/ForbiddenIETest.php rename to tests/HttpTest/MiddlewareTest/EnforceEverGreenTest.php index 4cbae52d..4d917404 100644 --- a/tests/HttpTest/MiddlewareTest/ForbiddenIETest.php +++ b/tests/HttpTest/MiddlewareTest/EnforceEverGreenTest.php @@ -2,7 +2,7 @@ namespace Tests; -class ForbiddenIETest extends TestCase +class EnforceEverGreenTest extends TestCase { public function testHandle() { @@ -10,5 +10,8 @@ class ForbiddenIETest extends TestCase ->assertSee(trans('errors.http.ie')); $this->get('/', ['user-agent' => 'Trident']) ->assertSee(trans('errors.http.ie')); + $this->get('/', [ + 'user-agent' => 'AppleWebKit/537.36 Chrome/54.0.2403.157 Safari/537.36', + ])->assertSee(trans('errors.http.ie')); } }