Skip to content

Commit

Permalink
Fixed issue: On group/question preview a PHP error is thrown if the q…
Browse files Browse the repository at this point in the history
…id/gid is invalid
  • Loading branch information
c-schmitz committed May 15, 2024
1 parent 8e8dde9 commit 6a4b289
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions application/controllers/SurveysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function spitOutHtmlError(array $error, $surveyId)
/* CRSF issue */
$title = gT('400: Bad Request');
$message = gT('The request could not be understood by the server due to malformed syntax.')
. gT('Please do not repeat the request without modifications.');
. ' ' . gT('Please do not repeat the request without modifications.');
break;
case '401':
$title = gT('401: Unauthorized');
Expand Down Expand Up @@ -156,7 +156,9 @@ public function spitOutHtmlError(array $error, $surveyId)
}
$aError['type'] = $error['code'];
$aError['error'] = $title;
$aError['title'] = nl2br(CHtml::encode($error['message']) ?? '');
if (!empty($error['message'])) {
$aError['title'] = ' - ' . nl2br(CHtml::encode($error['message']) ?? '');
}
$aError['message'] = $message;
$aError['contact'] = $contact;

Expand Down
14 changes: 12 additions & 2 deletions application/controllers/survey/SurveyIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,18 @@ public function action()
throw new CHttpException(401, $message);
} else {
killSurveySession($surveyid);
if ((intval($param['qid']) && $param['action'] == 'previewquestion')) {
// Check if group exists
$arGroup = QuestionGroup::model()->findByPk(intval($param['gid']));
if (empty($arGroup)) {
throw new CHttpException(400, gT("Invalid group ID"));
}
if ($param['action'] == 'previewquestion') {
$previewmode = 'question';
// Check if question exists
$arQuestion = Question::model()->findByPk(intval($param['qid']));
if (empty($arQuestion)) {
throw new CHttpException(400, gT("Invalid question ID"));
}
}
if ((intval($param['gid']) && $param['action'] == 'previewgroup')) {
$previewmode = 'group';
Expand Down Expand Up @@ -649,7 +659,7 @@ public function action()
private function getParameters($args = array(), $post = array())
{
$param = array();
if (@$args[0] == __CLASS__) {
if (isset($args[0]) && $args[0] == __CLASS__) {
array_shift($args);
}
$iArgCount = count($args);
Expand Down
2 changes: 1 addition & 1 deletion application/core/SurveyCommonAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private function addPseudoParams($params)
if (!empty($params['iGroupId'])) {
if ((string) (int) $params['iGroupId'] !== (string) $params['iGroupId']) {
// pgsql need filtering before find
throw new CHttpException(403, gT("Invalid group id"));
throw new CHttpException(403, gT("Invalid group ID"));
}
$oGroup = QuestionGroup::model()->find("gid=:gid", array(":gid" => $params['iGroupId'])); //Move this in model to use cache
if (!$oGroup) {
Expand Down

0 comments on commit 6a4b289

Please sign in to comment.