Commit d217ff6f authored by paalj's avatar paalj Committed by Pål Jørgensen

HFJ-147: Fixed regexp escaping problem, and improved feedback when regexp does...

HFJ-147: Fixed regexp escaping problem, and improved feedback when regexp does not match (drupal_set_message)
parent 8dc9db92
......@@ -1481,12 +1481,12 @@ class H5PContentValidator {
// Check if string is according to optional regexp in semantics
if (isset($semantics->regexp)) {
// Escaping '/' found in patterns, so that it does not break regexp fencing.
$pattern = '/' . preg_quote($semantics->regexp->pattern, '/') . '/';
$pattern = '/' . str_replace('/', '\\/', $semantics->regexp->pattern) . '/';
$pattern .= isset($semantics->regexp->modifiers) ? $semantics->regexp->modifiers : '';
if (preg_match($pattern, $text) === 0) {
// Note: explicitly ignore return value FALSE, to avoid removing text
// if regexp is invalid...
$this->h5pF->setErrorMessage($this->h5pF->t('Provided string is not valid according to regexp in semantics.'));
$this->h5pF->setErrorMessage($this->h5pF->t('Provided string is not valid according to regexp in semantics. (value: "%value", regexp: "%regexp")', array('%value' => $text, '%regexp' => $pattern)));
$text = '';
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment