From 8bf7ad382cac5b73817dae613871486b81b02dda Mon Sep 17 00:00:00 2001 From: Spomsoree Date: Thu, 31 Oct 2019 16:05:31 +0100 Subject: [PATCH] Added a try catch to the config parsing to avoid crashes on invalid configurations --- .gitignore | 1 + src/Config/Redirect.php | 6 +++++- src/Redirector/Redirector.php | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a3083d8..7717dc6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ config.yml composer.lock vendor/ diff --git a/src/Config/Redirect.php b/src/Config/Redirect.php index 9edcdb2..2e7feed 100644 --- a/src/Config/Redirect.php +++ b/src/Config/Redirect.php @@ -90,7 +90,11 @@ public function prepare() */ public function match($path) { - return preg_match("~^" . $this->computedWildcards . "$~i", $path); + try { + return preg_match("~^" . $this->computedWildcards . "$~i", $path); + } catch (\Exception $exception) { + return false; + } } /** diff --git a/src/Redirector/Redirector.php b/src/Redirector/Redirector.php index 04e6acb..1f94f61 100644 --- a/src/Redirector/Redirector.php +++ b/src/Redirector/Redirector.php @@ -37,8 +37,13 @@ public function handle(Request $request, Application $app) foreach ($this->config->getRedirects() as $redirect) { $redirect->prepare(); + $match = $redirect->match($path); - if ($redirect->match($path)) { + if ($match === false) { + $app['logger.flash']->error('Error while parsing the boltredirector configuration.'); + } + + if ($match) { $result = $redirect->getResult($path); $status = $redirect->getStatusCode();