Skip to content

Commit

Permalink
Merge pull request #114 from JarvusInnovations/develop
Browse files Browse the repository at this point in the history
Release: gatekeeper v2.5.3
  • Loading branch information
themightychris authored Mar 7, 2021
2 parents ef9563f + 051b1f8 commit 577a65a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions php-classes/Gatekeeper/Endpoints/EndpointRewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gatekeeper\Endpoints;

use Cache;
use RecordValidator;

class EndpointRewrite extends \ActiveRecord
{
Expand Down Expand Up @@ -41,8 +42,7 @@ class EndpointRewrite extends \ActiveRecord
'Endpoint' => 'require-relationship',
'Pattern' => [
'validator' => 'regexp',
'regexp' => '/^(.).+\1[a-zA-Z]*$/',
'errorMessage' => 'Pattern must include matching delimiters'
'validator' => [__CLASS__, 'validatePattern']
],
'Priority' => [
'required' => false,
Expand All @@ -67,4 +67,17 @@ public function destroy()
Cache::delete("endpoints/$this->EndpointID/rewrites");
return $success;
}

public static function validatePattern(RecordValidator $validator, EndpointRewrite $EndpointRewrite)
{
if (!preg_match('/^(.).+\1[a-zA-Z]*$/', $EndpointRewrite->Pattern)) {
$validator->addError('Pattern', 'Pattern must include matching delimiters');
return;
}

if (@preg_match($EndpointRewrite->Pattern, null) === false) {
$validator->addError('Pattern', 'Pattern must valid PCRE regex');
return;
}
}
}

0 comments on commit 577a65a

Please sign in to comment.