Escape '|' characters in regexp

namespaces
Frank Ronny Larsen 2013-11-13 15:35:10 +01:00
parent 44b5d89970
commit d9532a44ed
1 changed files with 3 additions and 1 deletions

View File

@ -1240,7 +1240,9 @@ class H5PContentValidator {
// Check if string is according to optional regexp in semantics
if (isset($semantics->regexp)) {
$pattern = '|' . $semantics->regexp->pattern . '|';
// Note: '|' used as regexp fence, to allow / in actual patterns.
// But also escaping '|' found in patterns, so that is valid too.
$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