Added checks for mbstring PHP extension [HFJ-1996]

pull/22/head
Paal Joergensen 2016-06-08 11:28:07 +02:00
parent f6ce5dff74
commit 6caf44e54b
1 changed files with 11 additions and 2 deletions

View File

@ -2898,8 +2898,13 @@ class H5PContentValidator {
// Check if string is within allowed length // Check if string is within allowed length
if (isset($semantics->maxLength)) { if (isset($semantics->maxLength)) {
if (!extension_loaded('mbstring')) {
$this->h5pF->setErrorMessage($this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly'), 'error');
}
else {
$text = mb_substr($text, 0, $semantics->maxLength); $text = mb_substr($text, 0, $semantics->maxLength);
} }
}
// Check if string is according to optional regexp in semantics // Check if string is according to optional regexp in semantics
if (!($text === '' && isset($semantics->optional) && $semantics->optional) && isset($semantics->regexp)) { if (!($text === '' && isset($semantics->optional) && $semantics->optional) && isset($semantics->regexp)) {
@ -2948,7 +2953,11 @@ class H5PContentValidator {
// file name, 2. testing against a returned error array that could // file name, 2. testing against a returned error array that could
// never be more than 1 element long anyway, 3. recreating the regex // never be more than 1 element long anyway, 3. recreating the regex
// for every file. // for every file.
if (!preg_match($wl_regex, mb_strtolower($file))) { if (!extension_loaded('mbstring')) {
$this->h5pF->setErrorMessage($this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly'), 'error');
$valid = FALSE;
}
else if (!preg_match($wl_regex, mb_strtolower($file))) {
$this->h5pF->setErrorMessage($this->h5pF->t('File "%filename" not allowed. Only files with the following extensions are allowed: %files-allowed.', array('%filename' => $file, '%files-allowed' => $whitelist)), 'error'); $this->h5pF->setErrorMessage($this->h5pF->t('File "%filename" not allowed. Only files with the following extensions are allowed: %files-allowed.', array('%filename' => $file, '%files-allowed' => $whitelist)), 'error');
$valid = FALSE; $valid = FALSE;
} }