Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-18423

Problem importing AIKEN format questions beginning with "U.S."

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.9.3, 1.9.4
    • 1.9.5
    • Questions
    • None
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE
    • Easy

    Description

      The REGEX for importing AIKEN questions will catch a question beginning with "U.S." since it's looking for '/[A-Z][).]/' at the beginning of the line to match an answer. This causes the question import screen to stop rendering the page, with no error output message.

      A solution is to change line 49 of /question/format/aiken/format.php from:

      if (preg_match('/[A-Z][).]/',$leader)){

      to

      if (preg_match('/^[A-Z][).] /',$nowline)){

      Note the extra space after the [).]. This should still comply with the AIKEN format, and won't match false positives. I also noticed that line 56 asks if ($leader == "AN"){. This would break if a question began with "AN". While this is somewhat unlikely, it could come up.

      I have attached a replacement format.php file with changes that will fix both issue. Please consider these changes. The diff is pasted below:

      48,49c48
      < $leader = substr($nowline,0,2);
      < if (preg_match('/[A-Z][).]/',$leader)){

      > if (preg_match('/^[A-Z][).] (.+)$/',$nowline, $match)){
      51c50
      < $question->answer[] = htmlspecialchars(trim(substr($nowline,2)), ENT_NOQUOTES);

      > $question->answer[] = htmlspecialchars($match[1], ENT_NOQUOTES);
      56,59c55,57
      < if ($leader == "AN"){
      < $ans = trim(substr($nowline,strpos($nowline,':') + 1));
      < $ans = substr($ans,0,1);
      < //A becomes 0 since array starts from 0

      > if (preg_match('/^ANSWER: ([A-Z])/', $nowline, $match) ){
      > $ans = $match[1];
      > //A becomes 0 since array starts from 0

      Attachments

        Activity

          People

            timhunt Tim Hunt
            aaronpk Aaron Parecki
            Jérôme Mouneyrac Jérôme Mouneyrac
            Tim Hunt, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              13/May/09