MDL-68883 filter_displayh5p: Ensure wwwroot is preg_quoted properly
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 2 Jun 2020 00:23:13 +0000 (08:23 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 2 Jun 2020 00:23:15 +0000 (08:23 +0800)
The character used as a preg_* delimter is the tilde (~) char, but this
was not passed into the `preg_quote()` when taking the user input
($CFG->wwwroot).

As a result, any site which uses a userdir fails to parse the regexp.

filter/displayh5p/filter.php

index 8d85c1c..f693b3c 100644 (file)
@@ -65,7 +65,7 @@ class filter_displayh5p extends moodle_text_filter {
         $allowedsources = get_config('filter_displayh5p', 'allowedsources');
         $allowedsources = array_filter(array_map('trim', explode("\n", $allowedsources)));
 
-        $localsource = '('.preg_quote($CFG->wwwroot).'/[^ &\#"\'<]*\.h5p([?][^ "\'<]*)?[^ \#"\'<]*)';
+        $localsource = '('.preg_quote($CFG->wwwroot, '~').'/[^ &\#"\'<]*\.h5p([?][^ "\'<]*)?[^ \#"\'<]*)';
         $allowedsources[] = $localsource;
 
         $params = array(