# Cloze (multianswer) question special character issues

## Details

• Type: Bug
• Status: Closed
• Priority: Minor
• Resolution: Fixed
• Affects Version/s: 1.6.1
• Fix Version/s:
• Component/s:
• Labels:
None
• Affected Branches:
MOODLE_16_STABLE
• Fixed Branches:
MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

## Description

I try to edit a cloze question with TeX fragments in it. For example $$a over {a+2}$$. Note that all special characters '\,

{,}

' are properly escaped. And it also works - I see the preview correctly.

However, when I afterwards try to edit the question once again, all special characters do not contain backslashes in front of them. I see something like: $$a \over {a+2}$$. The question is then not displayed correctly.

Thus, in each editing, all backslashes needs be added again.

## Attachments

1. questiontype1.6.php
30 kB
2. questiontype1.7.php
30 kB
3. questiontype1.8.php
31 kB
4. screenshot-1.jpg
53 kB

## Activity

Hide
Manish Verma added a comment -

Originally, it is mentioned that the issue affects version 1.6.1 but I have noticed it in 1.7 as well.

Show
Manish Verma added a comment - Originally, it is mentioned that the issue affects version 1.6.1 but I have noticed it in 1.7 as well.
Hide
Miroslav Fikar added a comment -

MDL-8127 addresses the same issue. The proposed solution is to change twice function call of stripslashes to stripslashes_safe. I have tried the proposed solution in Moodle 1.6.4+ and it seems to work for me. The change involves function moodle/question/type/multianswer/questiontype.php and lines (in 1.6.4+) 656 and 676. Finally!.

Show
Miroslav Fikar added a comment - MDL-8127 addresses the same issue. The proposed solution is to change twice function call of stripslashes to stripslashes_safe. I have tried the proposed solution in Moodle 1.6.4+ and it seems to work for me. The change involves function moodle/question/type/multianswer/questiontype.php and lines (in 1.6.4+) 656 and 676. Finally!.
Hide
Tim Hunt added a comment -

Note that the issues marked as duplicates actually describe slightly different aspects of this same problem.

Show
Tim Hunt added a comment - Note that the issues marked as duplicates actually describe slightly different aspects of this same problem.
Hide
Tim Hunt added a comment -

I think I have managed to fix this issue, and the two linked ones. However, I don't use close questions myself, and so have only been able to do minimal testing.

Please could you download and test one attached versions of questiontype.php. You need to download the file questiontype1.x.php (which file you need depends on which version of Moodle you are using), rename it to questiontype.php, and copy it into the question/type/multianswer folder to replace the existing file. Then make sure that all your cloze questions work.

Show
Tim Hunt added a comment - I think I have managed to fix this issue, and the two linked ones. However, I don't use close questions myself, and so have only been able to do minimal testing. Please could you download and test one attached versions of questiontype.php. You need to download the file questiontype1.x.php (which file you need depends on which version of Moodle you are using), rename it to questiontype.php, and copy it into the question/type/multianswer folder to replace the existing file. Then make sure that all your cloze questions work.
Hide
Tim Hunt added a comment -

Note, the questiontype1.8.php file will also work on 1.9dev.

Thanks in anticipation for your help in testing. This is a fairly risky change, so I would like quite a lot of testing before it is checked in. If we can get that testing in the next few days, we can get it in before Moodle 1.8 is released.

Show
Tim Hunt added a comment - Note, the questiontype1.8.php file will also work on 1.9dev. Thanks in anticipation for your help in testing. This is a fairly risky change, so I would like quite a lot of testing before it is checked in. If we can get that testing in the next few days, we can get it in before Moodle 1.8 is released.
Hide
Joseph Rézeau added a comment -

Results of my tests using the 3 patch files proposed by Tim.

This is the exact text I have used in my multianswer/cloze type question for my tests:

In this multianswer question text we have 3 backslashes \\\ followed by

{curled braces}

<angle brackets> and 3 non-breaking spaces & finally one non?breaking hyphen. The SHORTANSWER sub-questions contains an apostrophe in the Correct answer text: John's book and apostrophes and double quotes in the feedback to that Correct answer: Yes, "John's book" is the correct answer.

.

Results
1- The non-breaking space no longer crashes the cloze questions; the backslashes are correctly displayed, even upon re-editing the question; angle brackets remain angle brackets (i.e. their contents is no longer interpreted as HTML tags), curled braces are OK. Everything is OK in 1.6, 1.7 and 1.8 versions.

2- When apostrophes or double quotes are used in the Feedback text of the sub-questions.
a- apostrophes are displayed OK in all versions
b- double quotes are displayed OK in 1.7 and 1.8 (not in 1.6)
c- when a cloze question with apostrophes or double quotes in one of its feedback messages is exported/imported (Moodle XML format), upon importing the question, the feedback message is no longer displayed. However, it will be correctly displayed if one edits the question (in fact, just edit and save, nothing must be changed). Weird.

3- There remains a bug I mentioned quite some time ago: SHORTANSWER sub-questions cannot have apostrophes or double-quotes in their ANSWER text
a- the apostrophe case: a backslash is added upon clicking Fill with correct in Question preview mode (see attached screenshot)
b- the double quote case: the double quotes are transformed into their HTML entity name!
NOTE.- Unfortunately it seems that the contents of SHORTANSWER sub-questions ANSWERS is strictly limited to text.
I had found a solution for the apostrophe, and will try to find it again, based on the patches now proposed by Tim in the present bug report.

NOTE.- I have not tested these patches with LaTex expressions in the Cloze question text because I never use LaTex and I am not able to make it work on my local Moodle server.

Joseph

Show
Hide
Joseph Rézeau added a comment -

a. the 3 non-breaking spaces show OK
b. there even is a non-breaking hyphen, OK too
c. note the unwanted backslash added to correct answer before the apostrophe
d. double-quotes and apostrophe correctly displayed in feedback text

Show
Joseph Rézeau added a comment - a. the 3 non-breaking spaces show OK b. there even is a non-breaking hyphen, OK too c. note the unwanted backslash added to correct answer before the apostrophe d. double-quotes and apostrophe correctly displayed in feedback text
Hide
Tim Hunt added a comment -

Thank you very much for your detailed testing.

And it was really helpful that you pasted your test question text in you comment. I wish everyone did that.

I cannot reproduce problem 3a) backslashed apostrophe on fill with correct. That is testing on 1.7.1+

My change is clearly a big step forwards. I am going to commit it and then close this bug. Can we open new separate issues for any remaining problems (or add comments to the existing bug reports).

Show
Tim Hunt added a comment - Thank you very much for your detailed testing. And it was really helpful that you pasted your test question text in you comment. I wish everyone did that. I cannot reproduce problem 3a) backslashed apostrophe on fill with correct. That is testing on 1.7.1+ My change is clearly a big step forwards. I am going to commit it and then close this bug. Can we open new separate issues for any remaining problems (or add comments to the existing bug reports).
Hide
Joseph Rézeau added a comment -

Tested with question/type/multianswer/questiontype.php just updated to:
<?php // $Id: questiontype.php,v 1.15.2.5 2007/03/15 12:59:20 tjhunt Exp$

bug 3a- is stil there (as shown on screen shot). When there is an apostrophe in the text of a SHORTANSWER sub-question, upon clicking Fill with correct, that apostrophe is backslashed. That is a "normal" apostrophe, not a smart or curly one.

Joseph

Show
Joseph Rézeau added a comment - Tested with question/type/multianswer/questiontype.php just updated to: <?php // $Id: questiontype.php,v 1.15.2.5 2007/03/15 12:59:20 tjhunt Exp$ bug 3a- is stil there (as shown on screen shot). When there is an apostrophe in the text of a SHORTANSWER sub-question, upon clicking Fill with correct, that apostrophe is backslashed. That is a "normal" apostrophe, not a smart or curly one. Joseph
Hide
Tim Hunt added a comment -

But when I test with your example question above, it works for me. I don't understand this at all.

Show
Tim Hunt added a comment - But when I test with your example question above, it works for me. I don't understand this at all.
Hide
Joseph Rézeau added a comment -

The apostrophe bug is another problem. I have re-opened MDL-6386 which provides a fix which should be re-applied!

Joseph

Show
Joseph Rézeau added a comment - The apostrophe bug is another problem. I have re-opened MDL-6386 which provides a fix which should be re-applied! Joseph

## People

• Assignee:
Tim Hunt
Reporter:
Miroslav Fikar
Tester:
Nobody
Participants: