From 6b4632d34a4c75377654967af9e51b60f50cc1ec Mon Sep 17 00:00:00 2001 From: Nathan Glasl Date: Thu, 25 Feb 2016 14:28:32 +1100 Subject: [PATCH] Correcting an issue where invalid regular expressions would cause PHP warnings. --- code/dataobjects/LinkMapping.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/dataobjects/LinkMapping.php b/code/dataobjects/LinkMapping.php index 408ade7..2928e91 100644 --- a/code/dataobjects/LinkMapping.php +++ b/code/dataobjects/LinkMapping.php @@ -281,10 +281,16 @@ public function getCMSFields() { public function validate() { $result = parent::validate(); - if($this->ValidateExternal && $this->RedirectLink && $result->valid() && !MisdirectionService::is_external_URL($this->RedirectLink)) { - // Use third party validation to determine an external URL (https://gist.github.com/dperini/729294 and http://mathiasbynens.be/demo/url-regex). + // Determine whether a regular expression mapping is possible to match against. + + if(($this->LinkType === 'Regular Expression') && $result->valid() && (!$this->MappedLink || !is_numeric(@preg_match("%{$this->MappedLink}%", null)))) { + $result->error('Invalid regular expression!'); + } + // Use third party validation to determine an external URL (https://gist.github.com/dperini/729294 and http://mathiasbynens.be/demo/url-regex). + + if($this->ValidateExternal && $this->RedirectLink && $result->valid() && !MisdirectionService::is_external_URL($this->RedirectLink)) { $result->error('External URL validation failed!'); }