Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,15 @@ function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext)
}

// Add leading and trailing regex marker automaticaly
if (isset($input['regex'])
&& !empty($input['regex'])) {
if (substr($input['regex'], 0, 1) != '/') {
if (substr($input['regex'], 0, 1) != '^') {
$input['regex'] = '/^' . $input['regex'];
} else {
$input['regex'] = '/' . $input['regex'];
}
}
if (substr($input['regex'], -1, 1) != '/') {
if (substr($input['regex'], -1, 1) != '$') {
$input['regex'] = $input['regex'] . '$/';
} else {
$input['regex'] = $input['regex'] . '/';
}
if (isset($input['regex']) && !empty($input['regex'])) {
// Avoid php notice when validating the regular expression
set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {});
$isValid = !(preg_match($input['regex'], null) === false);
restore_error_handler();

if (!$isValid) {
Session::addMessageAfterRedirect(__('The regular expression is invalid', 'formcreator'), false, ERROR);
return [];
}
}

Expand Down Expand Up @@ -492,6 +486,10 @@ public function prepareInputForUpdate($input) {
$input = $this->checkBeforeSave($input);
}

if (!is_array($input) || count($input) == 0) {
return false;
}

// generate a uniq id
if (!isset($input['uuid'])
|| empty($input['uuid'])) {
Expand Down