Commit 98fc5067 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Fix crash when giving answer with too few items

When the question has two or more blanks but the answer doesn't contain enough semicolon-separated items we would access the split list out-of-bounds
parent ec03f7fb
Pipeline #263810 passed with stage
in 50 seconds
......@@ -37,6 +37,14 @@ void YourAnswerTest::testYourAnswer_data()
QTest::addRow("two_blanks_filled") << "blanks;filled"
<< "Two .......... .........."
<< "<qt>Two <u>blanks</u> <u>filled</u></qt>";
QTest::addRow("two_blanks_one_filled") << "blanks"
<< "Two .......... .........."
<< "<qt>Two <u>blanks</u> <u></u></qt>";
QTest::addRow("two_blanks_empty") << ""
<< "Two .......... .........."
<< "<qt>Two <u></u> <u></u></qt>";
}
void YourAnswerTest::testYourAnswer()
......
......@@ -59,7 +59,7 @@ QString yourAnswerResult(const QString &givenAnswer, const QString &blankedAnswe
result = QString(blankedAnswer).replace(QLatin1String(".........."), QLatin1String("<u></u>"));
int offset = 0, counter = 0;
while (offset >= 0) {
while (offset >= 0 && counter < ls.size()) {
offset = result.indexOf(QStringLiteral("<u>"), offset);
if (offset >= 0) {
result.insert(offset + 3, ls[counter]);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment