From d9532a44edf5c320e70a6ece539aa63843f80f7d Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Wed, 13 Nov 2013 15:35:10 +0100 Subject: [PATCH] Escape '|' characters in regexp --- h5p.classes.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 51380ff..796a564 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -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