Skip to content

Commit

Permalink
PatternConstraint to escape early, refs #1417
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw authored and mwjames committed Jul 7, 2016
1 parent 03f0336 commit 789f974
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function validate( $dataValue ) {

private function doPregMatch( $pattern, $dataValue, $reference ) {

// Convert escaping as in /\d{4}
$pattern = str_replace( "/\\", "\\", $pattern );

// Add a mandatory backslash
if ( $pattern !== '' && $pattern{0} !== '/' ) {
$pattern = '/' . $pattern;
Expand All @@ -92,9 +95,6 @@ private function doPregMatch( $pattern, $dataValue, $reference ) {
$pattern = $pattern . '/';
}

// Convert escaping
$pattern = str_replace( "/\\", "\\", $pattern );

// @to suppress any errors caused by an invalid regex, the user should
// test the expression before making it available
if ( !@preg_match( $pattern, $dataValue->getDataItem()->getSortKey() ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ public function allowedPatternProvider() {
true
);

#4
$provider[] = array(
" \nFoo|\d{8}\n",
'00564222',
false
);

#5
$provider[] = array(
" \nFoo|/\d{8}\n",
'00564222',
false
);

return $provider;
}

Expand Down

0 comments on commit 789f974

Please sign in to comment.