Moodle
  1. Moodle
  2. MDL-29730

error in Lesson question shortanswer with regexp option

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0, 2.1.2
    • Fix Version/s: 2.0.7, 2.1.4
    • Component/s: Lesson
    • Labels:
      None
    • Testing Instructions:
      Hide

      #. login as admin/teacher
      #. create a lesson,
      #. set 'Provide option to try a question again' to yes
      #. set 'Display default feedback' to yes
      #. add shortanswer question
      #. tick on 'options' to use regular expression
      #. on answer 1 section, enter the following string: 'it's blue, white(,| and) red/i'
      #. save page
      #. preview the question and answer it with either one of these correct answers: 'it's blue, white, red' or 'it's blue, white and red'

      The above answers should be recognize as the correct answers.

      For more info regarding correct answer with regular expression: http://docs.moodle.org/20/en/Short_answer_analysis

      Show
      #. login as admin/teacher #. create a lesson, #. set 'Provide option to try a question again' to yes #. set 'Display default feedback' to yes #. add shortanswer question #. tick on 'options' to use regular expression #. on answer 1 section, enter the following string: 'it's blue, white(,| and) red/i' #. save page #. preview the question and answer it with either one of these correct answers: 'it's blue, white, red' or 'it's blue, white and red' The above answers should be recognize as the correct answers. For more info regarding correct answer with regular expression: http://docs.moodle.org/20/en/Short_answer_analysis
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      19245

      Description

      Error in mod/lesson/pagetypes/shortanswer.php line 88

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

      should be

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

        Activity

        Show
        Troy Williams added a comment - https://github.com/troywilliams/moodle/compare/MOODLE_20_STABLE...wip-MDL-29730-MOODLE_20_STABLE
        Hide
        Rossiani Wijaya added a comment -

        Hi Troy,

        Thank you for providing patch for this issue.

        However, when I tested the patch, it produced a warning message and make the correct answer to false :

        Warning: preg_match() [function.preg-match]: Unknown modifier '$' in /m20/moodle/mod/lesson/pagetypes/shortanswer.php on line 105
        

        Could you please try to address the above issue and provide new patch?

        Thanks
        Rosie

        Show
        Rossiani Wijaya added a comment - Hi Troy, Thank you for providing patch for this issue. However, when I tested the patch, it produced a warning message and make the correct answer to false : Warning: preg_match() [function.preg-match]: Unknown modifier '$' in /m20/moodle/mod/lesson/pagetypes/shortanswer.php on line 105 Could you please try to address the above issue and provide new patch? Thanks Rosie
        Hide
        Troy Williams added a comment -

        Hi Rosie,

        I have used examples from http://docs.moodle.org/20/en/Regular_Expression_Short-Answer_question_type, such as:

        Example 1 RegEx: it’s blue, white(,| and) red/i

        That was the error was getting before fix, I will check again at work tomorrow.

        Do you have an example I can use to check against please?

        Cheers

        Troy

        Show
        Troy Williams added a comment - Hi Rosie, I have used examples from http://docs.moodle.org/20/en/Regular_Expression_Short-Answer_question_type , such as: Example 1 RegEx: it’s blue, white(,| and) red/i That was the error was getting before fix, I will check again at work tomorrow. Do you have an example I can use to check against please? Cheers Troy
        Hide
        Rossiani Wijaya added a comment -

        Hi Troy,

        Ignore my previous comment. I applied the wrong patch to test this. Sorry.

        I will look at this issue again tomorrow and submitted for integration.

        Thank you for fixing this bug.

        Rosie.

        Show
        Rossiani Wijaya added a comment - Hi Troy, Ignore my previous comment. I applied the wrong patch to test this. Sorry. I will look at this issue again tomorrow and submitted for integration. Thank you for fixing this bug. Rosie.
        Hide
        Rossiani Wijaya added a comment -

        Hi Troy,

        Just looked at the issue again and you patch is working fine.

        However, I simplified the patch from:

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

        to

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

        Submitting patch for peer review.

        Show
        Rossiani Wijaya added a comment - Hi Troy, Just looked at the issue again and you patch is working fine. However, I simplified the patch from: if ( substr($expectedanswer,strlen($expectedanswer) - 2, 2) == '/i') to if (substr($expectedanswer, -2) == '/i') Submitting patch for peer review.
        Hide
        Adrian Greeve added a comment -

        The code looks good. I tested it and it works fine. Thanks Rossie.

        Show
        Adrian Greeve added a comment - The code looks good. I tested it and it works fine. Thanks Rossie.
        Hide
        Rossiani Wijaya added a comment -

        Thanks for reviewing adrian.

        Submitting for integration review.

        Show
        Rossiani Wijaya added a comment - Thanks for reviewing adrian. Submitting for integration review.
        Hide
        Sam Hemelryk added a comment -

        Thanks Rossi, this has been integrated now

        Show
        Sam Hemelryk added a comment - Thanks Rossi, this has been integrated now
        Hide
        Rajesh Taneja added a comment -

        Works Great
        Thanks for fixing this Rossie.

        Show
        Rajesh Taneja added a comment - Works Great Thanks for fixing this Rossie.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Sent upstream! Just in time for Moodle 2.2rc1 (if related), yay!

        Closing and big thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Sent upstream! Just in time for Moodle 2.2rc1 (if related), yay! Closing and big thanks!

          People

          • Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: