Moodle
  1. Moodle
  2. MDL-5485

Short answer with special characters

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: None
    • Component/s: Lesson
    • Labels:
      None
    • Environment:
      All
    • Affected Branches:
      MOODLE_16_STABLE
    • Rank:
      14817

      Description

      Creating a question page of type short answer, If I use some special character (I tried (, ) and %, but probably many others), the text inserted is not correctly compared; this is probably caused by the use of RegExp in the parsing; to resolve the problem I inserted backslash in the correct answer, like this:

      Il costo complessivo è di € 10,00 (inclusa iva 20%)

      Moreover, the use of jolly character * doesn't works: it has to be replaced by the use of the RegExp string (.*)

      I think that the software should do these replaces.

      File: http://moodle.cvs.sourceforge.net/moodle/moodle/mod/lesson/action/continue.php

        Activity

        Hide
        Martin Dougiamas added a comment -

        From Joseph R?zeau (joseph.rezeau at uhb.fr) Saturday, 13 May 2006, 07:35 PM:

        Hi Mark!

        This bug is all my fault. It dates back to when I proposed that Lesson Short Answer question type should be subdivided in 2 types, the simple and the regular expressions type. I should have checked it sooner...

        In order to solve both the problems of the wild card and the special characters (as reported by Stefano Pisu Bagnatica), I propose the following.

        a) In the Short Answer simple analysis type, the asterisk should only be used as a catch-all. If teachers need a wild card, then they should use the regular expressions type.

        b) When simple analysis type is being used, there should be no need to escape special characters in this list: .^$*()[]+?/

        c) In order to achieve this, we should modify \lesson\action\continue.php as follows.

        1- Around line 160: remove the lines dealing with the apostrophe. These lines should no longer be there:

        // prevent the potential apostrophe problem!

        if (preg_match_all(/'/,$expectedanswer, $matches))

        { $expectedanswer = ereg_replace(', \\\', $expectedanswer); }

        2- Around line 167:

        replace:

        if (preg_match('/^'.$expectedanswer.'$/i',$useranswer))

        with:

        if (strcasecmp($expectedanswer, $useranswer) == 0) {

        3- Around line 192

        replace:

        if (preg_match('/^'.$expectedanswer.'$/i',$useranswer))

        with:

        if ($expectedanswer == '*' / strcasecmp($expectedanswer, $useranswer) == 0) {

        4- In file \lang\...\help\lesson\questiontypes.html

        replace the whole of Short Answer / Simple analysis with this:

        In this (default) system of analysis, the comparisons ignore the case of the text. The asterisk character can be used in answers as a catch all character. If you enter a single asterisk as the last possible Answer in a series of expected Answers, the corresponding Response will be displayed for any student answer different from any of the expected answers. This is a way to over-ride the default That's the Wrong Answer response message.

        5- I am attaching modified versions of \lesson\action\continue.php and \lang\...\help\lesson\questiontypes.html

        If you agree with my reasoning, I hope you will be able to commit the new versions to Moodle 1.6 beta 5 before it becomes 1.6 STABLE (any time soon).

        Thanks,

        Joseph

        From Mark Nielsen (man15 at humboldt.edu) Tuesday, 16 May 2006, 12:59 AM:

        Hi Joeseph,

        One problem of dropping support for the wild card for the simple analysis is that old short answers would then be broken Then again, we sort of broke them already by changing it from case sensitive to regular expressions.

        Could we do something like this for simple analysis:

        $answer = str_replace('*', '#####', $answer);

        $answer = preg_quote($answer);

        $answer = str_replace('#####', '.*', $answer);

        // preform preg_match's by using $answer as reg expression

        // against the student answer

        First thing that comes to mind. What do you think?

        From Joseph R?zeau (joseph.rezeau at uhb.fr) Tuesday, 16 May 2006, 05:48 AM:

        Hi Mark,

        >One problem of dropping support for the wild card for the simple analysis is that old short answers would then be broken.

        JR: You are quite right!

        >Could we do something like this for simple analysis:

        $answer = str_replace('*', '#####', $answer);

        $answer = preg_quote($answer);

        $answer = str_replace('#####', '.*', $answer);

        JR: Excellent! I did not know of the preg_quote function, just what is needed here.

        So, my previous message suggestions now become:

        1-Around line 160: remove the lines dealing with the apostrophe. (we still need to remove these lines)

        2- & 3-

        Around line 153, add an else {} condition:

        if ($useregexp) {

        $ignorecase = '';

        if ( substr($expectedanswer,strlen($expectedanswer) - 2, 2) == '/i')

        { $expectedanswer = substr($expectedanswer,0,strlen($expectedanswer) - 2); $ignorecase = 'i'; }

        } else { $expectedanswer = str_replace('*', '#####', $expectedanswer); $expectedanswer = preg_quote($expectedanswer); $expectedanswer = str_replace('#####', '.*', $expectedanswer); }



        4- Do NOT change anything in the help files!



        Please test it again and, if OK commit it to CVS for 1.6 beta 5.



        Thanks a lot,



        Joseph

        From Joseph R?zeau (joseph.rezeau at uhb.fr) Tuesday, 16 May 2006, 06:03 AM:

        CORRECTION!

        Just discovered that the slash character / must also be escaped if present in expected answer. Example Question: re-write 0.5 as a fraction; expected answer: 1/2.

        This is achieved by adding the slash delimiter to the preg_quote() expression, like this:

        $expectedanswer = preg_quote($expectedanswer, '/');

        ----------------------------

        MODIFIED MODIFICATION is now:



        Around line 153, add an else {} condition:

        if ($useregexp) {

        $ignorecase = '';

        if ( substr($expectedanswer,strlen($expectedanswer) - 2, 2) == '/i') { $expectedanswer = substr($expectedanswer,0,strlen($expectedanswer) - 2); $ignorecase = 'i'; }

        } else

        { $expectedanswer = str_replace('*', '#####', $expectedanswer); $expectedanswer = preg_quote($expectedanswer, '/'); $expectedanswer = str_replace('#####', '.*', $expectedanswer); }

        From Mark Nielsen (man15 at humboldt.edu) Tuesday, 16 May 2006, 11:08 AM:

        Excellent! Works fine for me, so its in MOODLE_16_STABLE and HEAD. Closing for now

        Thanks for you great work on this Joseph!

        Show
        Martin Dougiamas added a comment - From Joseph R?zeau (joseph.rezeau at uhb.fr) Saturday, 13 May 2006, 07:35 PM: Hi Mark! This bug is all my fault. It dates back to when I proposed that Lesson Short Answer question type should be subdivided in 2 types, the simple and the regular expressions type. I should have checked it sooner... In order to solve both the problems of the wild card and the special characters (as reported by Stefano Pisu Bagnatica), I propose the following. a) In the Short Answer simple analysis type, the asterisk should only be used as a catch-all. If teachers need a wild card, then they should use the regular expressions type. b) When simple analysis type is being used, there should be no need to escape special characters in this list: .^$*()[]+?/ c) In order to achieve this, we should modify \lesson\action\continue.php as follows. 1- Around line 160: remove the lines dealing with the apostrophe. These lines should no longer be there: // prevent the potential apostrophe problem! if (preg_match_all(/'/,$expectedanswer, $matches)) { $expectedanswer = ereg_replace(', \\\', $expectedanswer); } 2- Around line 167: replace: if (preg_match('/^'.$expectedanswer.'$/i',$useranswer)) with: if (strcasecmp($expectedanswer, $useranswer) == 0) { 3- Around line 192 replace: if (preg_match('/^'.$expectedanswer.'$/i',$useranswer)) with: if ($expectedanswer == '*' / strcasecmp($expectedanswer, $useranswer) == 0) { 4- In file \lang\...\help\lesson\questiontypes.html replace the whole of Short Answer / Simple analysis with this: In this (default) system of analysis, the comparisons ignore the case of the text. The asterisk character can be used in answers as a catch all character. If you enter a single asterisk as the last possible Answer in a series of expected Answers, the corresponding Response will be displayed for any student answer different from any of the expected answers. This is a way to over-ride the default That's the Wrong Answer response message. 5- I am attaching modified versions of \lesson\action\continue.php and \lang\...\help\lesson\questiontypes.html If you agree with my reasoning, I hope you will be able to commit the new versions to Moodle 1.6 beta 5 before it becomes 1.6 STABLE (any time soon). Thanks, Joseph From Mark Nielsen (man15 at humboldt.edu) Tuesday, 16 May 2006, 12:59 AM: Hi Joeseph, One problem of dropping support for the wild card for the simple analysis is that old short answers would then be broken Then again, we sort of broke them already by changing it from case sensitive to regular expressions. Could we do something like this for simple analysis: $answer = str_replace('*', '#####', $answer); $answer = preg_quote($answer); $answer = str_replace('#####', '.*', $answer); // preform preg_match's by using $answer as reg expression // against the student answer First thing that comes to mind. What do you think? From Joseph R?zeau (joseph.rezeau at uhb.fr) Tuesday, 16 May 2006, 05:48 AM: Hi Mark, >One problem of dropping support for the wild card for the simple analysis is that old short answers would then be broken. JR: You are quite right! >Could we do something like this for simple analysis: $answer = str_replace('*', '#####', $answer); $answer = preg_quote($answer); $answer = str_replace('#####', '.*', $answer); JR: Excellent! I did not know of the preg_quote function, just what is needed here. So, my previous message suggestions now become: 1-Around line 160: remove the lines dealing with the apostrophe. (we still need to remove these lines) 2- & 3- Around line 153, add an else {} condition: if ($useregexp) { $ignorecase = ''; if ( substr($expectedanswer,strlen($expectedanswer) - 2, 2) == '/i') { $expectedanswer = substr($expectedanswer,0,strlen($expectedanswer) - 2); $ignorecase = 'i'; } } else { $expectedanswer = str_replace('*', '#####', $expectedanswer); $expectedanswer = preg_quote($expectedanswer); $expectedanswer = str_replace('#####', '.*', $expectedanswer); } 4- Do NOT change anything in the help files! Please test it again and, if OK commit it to CVS for 1.6 beta 5. Thanks a lot, Joseph From Joseph R?zeau (joseph.rezeau at uhb.fr) Tuesday, 16 May 2006, 06:03 AM: CORRECTION! Just discovered that the slash character / must also be escaped if present in expected answer. Example Question: re-write 0.5 as a fraction; expected answer: 1/2. This is achieved by adding the slash delimiter to the preg_quote() expression, like this: $expectedanswer = preg_quote($expectedanswer, '/'); ---------------------------- MODIFIED MODIFICATION is now: Around line 153, add an else {} condition: if ($useregexp) { $ignorecase = ''; if ( substr($expectedanswer,strlen($expectedanswer) - 2, 2) == '/i') { $expectedanswer = substr($expectedanswer,0,strlen($expectedanswer) - 2); $ignorecase = 'i'; } } else { $expectedanswer = str_replace('*', '#####', $expectedanswer); $expectedanswer = preg_quote($expectedanswer, '/'); $expectedanswer = str_replace('#####', '.*', $expectedanswer); } From Mark Nielsen (man15 at humboldt.edu) Tuesday, 16 May 2006, 11:08 AM: Excellent! Works fine for me, so its in MOODLE_16_STABLE and HEAD. Closing for now Thanks for you great work on this Joseph!
        Hide
        Michael Blake added a comment -

        transition from old defect tracking system

        Show
        Michael Blake added a comment - transition from old defect tracking system
        Hide
        Michael Blake added a comment -

        transition from old defect tracking system

        Show
        Michael Blake added a comment - transition from old defect tracking system

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: