]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18552 different TeX trouble fix
authorskodak <skodak>
Tue, 31 Mar 2009 10:03:10 +0000 (10:03 +0000)
committerskodak <skodak>
Tue, 31 Mar 2009 10:03:10 +0000 (10:03 +0000)
filter/tex/filter.php
filter/tex/latex.php
filter/tex/lib.php
lang/en_utf8/error.php
lib/db/upgrade.php
version.php

index 646d8109d626a31f7dd3c669ff5c5abbf26b2eed..01ee633d77edba4992e34722067f56730b0cc591 100644 (file)
@@ -137,16 +137,6 @@ class tex_filter extends filter_base {
             $text = str_replace($matches[0][$i],$replacement,$text);
         }
 
-        // TeX blacklist. MDL-18552
-        $tex_blacklist = array(
-            'include','def','command','loop','repeat','open','toks','output',
-            'input','catcode','name','^^',
-            '\every','\errhelp','\errorstopmode','\scrollmode','\nonstopmode',
-            '\batchmode','\read','\write','csname','\newhelp','\uppercase',
-            '\lowercase','\relax','\aftergroup',
-            '\afterassignment','\expandafter','\noexpand','\special'
-        );
-
         // <tex> TeX expression </tex>
         // or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
         // or $$ TeX expression $$
@@ -169,19 +159,6 @@ class tex_filter extends filter_base {
               $align = "text-top";
               $texexp = preg_replace('/^align=top /','',$texexp);
             }
-        /// Check $texexp against blacklist (whitelisting could be more complete but also harder to maintain). MDL-18552
-            $invalidcommands = array();
-            foreach($tex_blacklist as $command) {
-                if (stristr($texexp, $command)) { /// Found invalid command. Annotate.
-                    $invalidcommands[] = $command;
-                }
-            }
-            if (!empty($invalidcommands)) { /// Invalid commands found. Output error and continue with next TeX element
-                $invalidstr = get_string('invalidtexcommand', 'error', implode(', ', $invalidcommands));
-                $text = str_replace( $matches[0][$i], $invalidstr, $text);
-                continue;
-            }
-        /// Everything is ok, let's process the expression
             $md5 = md5($texexp);
             if (! $texcache = $DB->get_record("cache_filters", array("filter"=>"tex", "md5key"=>$md5))) {
                 $texcache->filter = 'tex';
index b476683bda50c526571ef9f74e331cab5d07b452..5386b2b9862282c92b25290a66be121f71723244 100644 (file)
          * @return string the latex document
          */
         function construct_latex_document( $formula, $fontsize=12 ) {
-            // $fontsize don't affects to formula's size. $density can change size
-
             global $CFG;
+
+            $formula = tex_sanitize_formula($formula);
+
+            // $fontsize don't affects to formula's size. $density can change size
             $doc =  "\\documentclass[{$fontsize}pt]{article}\n"; 
             $doc .=  $CFG->filter_tex_latexpreamble;
             $doc .= "\\pagestyle{empty}\n";
index db6405bcd662a048b68569c5cbab1b751548071b..8cec92badca7f3a342f87ca32479cd1ca044e4b3 100644 (file)
@@ -34,8 +34,22 @@ function tex_filter_get_executable($debug=false) {
     print_error('mimetexisnotexist', 'error');
 }
 
+function tex_sanitize_formula($texexp) {
+    /// Check $texexp against blacklist (whitelisting could be more complete but also harder to maintain)
+    $tex_blacklist = array(
+        'include','def','command','loop','repeat','open','toks','output',
+        'input','catcode','name','^^',
+        '\every','\errhelp','\errorstopmode','\scrollmode','\nonstopmode',
+        '\batchmode','\read','\write','csname','\newhelp','\uppercase',
+        '\lowercase','\relax','\aftergroup',
+        '\afterassignment','\expandafter','\noexpand','\special'
+    );
+
+    return  str_ireplace($tex_blacklist, 'forbiddenkeyword', $texexp);
+}
 
 function tex_filter_get_cmd($pathname, $texexp) {
+    $texexp = tex_sanitize_formula($texexp);
     $texexp = escapeshellarg($texexp);
     $executable = tex_filter_get_executable(false);
 
index c37100bc5fc315cd653d8b9dd0affab494103d7c..023f984183e9eef60f4115d6c7bfdbe33f7e4716 100644 (file)
@@ -294,7 +294,6 @@ $string['invalidscaleid'] = 'Incorrect scale id';
 $string['invalidsesskey'] = 'Incorrect sesskey submitted, form not accepted!';
 $string['invalidsection'] = 'Course module record contains invalid section';
 $string['invalidshortname'] = 'That\'s an invalid short course name';
-$string['invalidtexcommand'] = 'Forbidden TeX command ($a)';
 $string['invalidurl'] = 'Invalid URL';
 $string['invaliduser'] = 'Invalid user';
 $string['invaliduserid'] = 'Invalid user id';
index 58899768be5148b70cd5a6e0bc2827921767b311..4944439624605729fd6fa011ef670b0a937b1a9a 100644 (file)
@@ -1534,7 +1534,14 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
     /// Main savepoint reached
         upgrade_main_savepoint($result, 2009032001);
     }
-    
+
+    if ($result && $oldversion < 2009033100) {
+        require_once("$CFG->dirroot/filter/tex/lib.php");
+        filter_tex_updatedcallback(null);
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2009033100);
+    }
+
     return $result;
 }
 
index 4f2461fe63e5d7f53ede6c24f86440bcf0d22d43..0baa74db9a1d713621d31c4097c29e2ea80fd28a 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009033002;  // YYYYMMDD   = date of the last version bump
+    $version = 2009033100;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090331)';  // Human-friendly version name