Skip to content

Commit b8be86b

Browse files
committed
GHI353_310 Ensuring clean text on new and existing essay questions.
1 parent bd188fa commit b8be86b

File tree

7 files changed

+121
-6
lines changed

7 files changed

+121
-6
lines changed

.github/workflows/ci.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Moodle plugin CI
2+
on: [push, pull_request]
3+
4+
jobs:
5+
test:
6+
runs-on: 'ubuntu-latest'
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
include:
11+
- php: '7.2'
12+
moodle-branch: 'MOODLE_39_STABLE'
13+
database: 'mariadb'
14+
node: '14.15.0'
15+
- php: '7.2'
16+
moodle-branch: 'MOODLE_39_STABLE'
17+
database: 'pgsql'
18+
node: '14.15.0'
19+
20+
services:
21+
postgres:
22+
image: postgres
23+
env:
24+
POSTGRES_USER: 'postgres'
25+
POSTGRES_HOST_AUTH_METHOD: 'trust'
26+
options: >-
27+
--health-cmd pg_isready
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 3
31+
ports:
32+
- 5432:5432
33+
34+
mariadb:
35+
image: mariadb:10.5
36+
env:
37+
MYSQL_USER: 'root'
38+
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
39+
ports:
40+
- 3306:3306
41+
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
42+
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v2
46+
with:
47+
path: plugin
48+
49+
- name: Install node
50+
uses: actions/setup-node@v1
51+
with:
52+
node-version: ${{ matrix.node }}
53+
54+
- name: Setup PHP
55+
uses: shivammathur/setup-php@v2
56+
with:
57+
php-version: ${{ matrix.php }}
58+
extensions: zip, gd, mbstring, pgsql, mysqli
59+
60+
- name: Deploy moodle-plugin-ci
61+
run: |
62+
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
63+
# Add dirs to $PATH
64+
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
65+
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
66+
# PHPUnit depends on en_AU.UTF-8 locale
67+
sudo locale-gen en_AU.UTF-8
68+
- name: Install Moodle
69+
# Need explicit IP to stop mysql client fail on attempt to use unix socket.
70+
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
71+
env:
72+
DB: ${{ matrix.database }}
73+
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
74+
IGNORE_NAMES: 'mobile_*.mustache'
75+
76+
- name: phplint
77+
if: ${{ always() }}
78+
run: moodle-plugin-ci phplint
79+
80+
- name: phpcpd
81+
if: ${{ always() }}
82+
run: moodle-plugin-ci phpcpd || true
83+
84+
- name: phpmd
85+
if: ${{ always() }}
86+
run: moodle-plugin-ci phpmd
87+
88+
- name: codechecker
89+
if: ${{ always() }}
90+
run: moodle-plugin-ci codechecker
91+
92+
- name: validate
93+
if: ${{ always() }}
94+
run: moodle-plugin-ci validate
95+
96+
- name: savepoints
97+
if: ${{ always() }}
98+
run: moodle-plugin-ci savepoints
99+
100+
- name: mustache
101+
if: ${{ always() }}
102+
run: moodle-plugin-ci mustache
103+
104+
- name: grunt
105+
if: ${{ always() }}
106+
run: moodle-plugin-ci grunt
107+
108+
- name: phpunit
109+
if: ${{ always() }}
110+
run: moodle-plugin-ci phpunit
111+
112+
- name: behat
113+
if: ${{ always() }}
114+
run: moodle-plugin-ci behat --profile chrome

classes/question/check.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function question_survey_display($response, $dependants, $blankquestio
139139
if ($choice->is_other_choice()) {
140140
$checkbox->oname = 'q'.$this->id.'['.$choice->other_choice_name().']';
141141
$checkbox->ovalue = (isset($response->answers[$this->id][$id]) && !empty($response->answers[$this->id][$id]) ?
142-
stripslashes($response->answers[$this->id][$id]->value) : '');
142+
format_text(stripslashes($response->answers[$this->id][$id]->value)) : '');
143143
$checkbox->label = format_text($choice->other_choice_display().'', FORMAT_HTML, ['noclean' => true]);
144144
}
145145
$choicetags->qelements[] = (object)['choice' => $checkbox];

classes/question/essay.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
108108
protected function response_survey_display($response) {
109109
if (isset($response->answers[$this->id])) {
110110
$answer = reset($response->answers[$this->id]);
111-
$answer = $answer->value;
111+
$answer = format_text($answer->value, FORMAT_HTML);
112112
} else {
113113
$answer = ' ';
114114
}

classes/question/radio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function question_survey_display($response, $dependants=[], $blankques
135135
$radio->oname = 'q'.$this->id.choice::id_other_choice_name($id);
136136
$radio->oid = $htmlid.'-other';
137137
if (isset($odata)) {
138-
$radio->ovalue = stripslashes($odata);
138+
$radio->ovalue = format_text(stripslashes($odata));
139139
}
140140
$radio->olabel = 'Text for '.format_text($othertext, FORMAT_HTML, ['noclean' => true]);
141141
}

classes/question/text.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
8585
if ($this->precise > 0) {
8686
$choice->maxlength = $this->precise;
8787
}
88-
$choice->value = (isset($response->answers[$this->id][0]) ? stripslashes($response->answers[$this->id][0]->value) : '');
88+
$choice->value = (isset($response->answers[$this->id][0]) ?
89+
format_text(stripslashes($response->answers[$this->id][0]->value)) : '');
8990
$choice->id = self::qtypename($this->type_id) . $this->id;
9091
$questiontags->qelements->choice = $choice;
9192
return $questiontags;

classes/responsetype/single.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function insert_response($responsedata) {
123123
$record->response_id = $response->id;
124124
$record->question_id = $this->question->id;
125125
$record->choice_id = $answer->choiceid;
126-
$record->response = $answer->value;
126+
$record->response = clean_text($answer->value);
127127
$DB->insert_record('questionnaire_response_other', $record);
128128
}
129129
// Record the choice selection.

classes/responsetype/text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function insert_response($responsedata) {
8181
$record = new \stdClass();
8282
$record->response_id = $response->id;
8383
$record->question_id = $this->question->id;
84-
$record->response = $response->answers[$this->question->id][0]->value;
84+
$record->response = clean_text($response->answers[$this->question->id][0]->value);
8585
return $DB->insert_record(static::response_table(), $record);
8686
} else {
8787
return false;

0 commit comments

Comments
 (0)