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

Algebra filter is triggered also by Unified Diff change chunkes

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: 2.2.5, 2.3.2
    • Component/s: Filters
    • Labels:
      None
    • Environment:
      Any
    • Database:
      Any
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE

      Description

      Having added a diff -u output in a post on moodle.org I've fallen into this issue, better described in MDLSITE-1113.

      It appears the algebra filter allows a user to escape a "@@...@@" sequence by prepending an extra "@": since Unified Diff is a well-known format and users cannot edit this output before posting it in Moodle Community, the patch below will escape such sequences without the need of an extra prepended "@":

      --- algebra\filter.php.orig	Thu Nov 04 10:52:20 2010
      +++ algebra\filter.php	Thu Nov 04 10:51:53 2010
      @@ -114,10 +114,18 @@
       
           $text .= ' ';
       
      +    // Prepending @ to a @@..@... sequence avoid any conversion
           preg_match_all('/@(@@+)([^@])/',$text,$matches);
           for ($i=0;$i<count($matches[0]);$i++) {
               $replacement = str_replace('@','&#x00040;',$matches[1][$i]).$matches[2][$i];
               $text = str_replace($matches[0][$i],$replacement,$text);
      +    }
      +
      +    // Escape @@...@@ occurences when representing Unified Diff change chunkes
      +    preg_match_all('/@@ \-(\d+(,\d+)?) \+(\d+(,\d+)?) @@/',$text,$matches);
      +    for ($i=0; $i < count($matches[0]); $i++) {
      +        $replacement = str_replace('@', '&#x00040;', $matches[0][$i]);
      +        $text = str_replace($matches[0][$i], $replacement, $text);
           }
       
           // <algebra> some algebraic input expression </algebra>

      The same applies to HEAD branch.

      Matteo

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    10/Sep/12