[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 02 Dec 2002 16:39:30 -0000


matthew		Mon Dec  2 11:39:30 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Bugfix for escaping of special characters.  < and > must be translated to
  &lt; and &gt; before & is translated to &amp; because the code gets unescaped
  by the browser twice.  This current version works for cells like:
  
  if (X0<Z0) {
     "Less";
  } else {
     "Greater";
  }
  
  
  
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.150 loncom/interface/lonspreadsheet.pm:1.151
--- loncom/interface/lonspreadsheet.pm:1.150	Tue Nov 26 09:58:41 2002
+++ loncom/interface/lonspreadsheet.pm	Mon Dec  2 11:39:30 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.150 2002/11/26 14:58:41 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.151 2002/12/02 16:39:30 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -965,11 +965,9 @@
 	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
 	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
-        my $fm=$sheet->{'f'}->{'template_'.$_};
-        $fm=~s/[\'\"]/\&\#34;/g;
         push(@cols,{ name    => 'template_'.$_,
-                     formula => $fm,
-                     value   => $fm });
+                     formula => $sheet->{'f'}->{'template_'.$_},
+                     value   => $sheet->{'f'}->{'template_'.$_} });
     }
     return ($rowlabel,@cols);
 }
@@ -993,10 +991,8 @@
 	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
 	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
-        my $fm=$sheet->{'f'}->{$_.$n};
-        $fm=~s/[\'\"]/\&\#34;/g;
         push(@cols,{ name    => $_.$n,
-                     formula => $fm,
+                     formula => $sheet->{'f'}->{$_.$n},
                      value   => $sheet->{'values'}->{$_.$n}});
     }
     return ($rowlabel,@cols);
@@ -1019,10 +1015,8 @@
 	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
 	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
 	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
-        my $fm=$sheet->{'f'}->{$_.$n};
-        $fm=~s/[\'\"]/\&\#34;/g;
         push(@cols,{ name    => $_.$n,
-                     formula => $fm,
+                     formula => $sheet->{'f'}->{$_.$n},
                      value   => $sheet->{'values'}->{$_.$n}});
     }
     return ($rowlabel,@cols);
@@ -1257,9 +1251,17 @@
     if ($value =~ /^\s*$/ ) {
         $value = '<font color="'.$bgcolor.'">#</font>';
     }
+    &Apache::lonnet::logthis($name.' formula = '.$formula) if ($formula);
+    $formula =~ s/</\&lt;/g;
+    $formula =~ s/>/\&gt;/g;
+    $formula =~ s/\&/\&amp;/g;
+    $formula =~ s/\"/\&quot;/g;
+    $formula =~ s/\'/\&quot;/g;
     $formula =~ s/\n/\\n/gs;
-    $result .= '<a href="javascript:celledit(\''.
-        $name.'\',\''.$formula.'\');">'.$value.'</a>';
+    &Apache::lonnet::logthis($name.' formula = '.$formula) if ($formula);
+    $result .= "<a href=\"javascript:celledit(\'".
+        $name."','".$formula."');\">".$value."</a>";
+    &Apache::lonnet::logthis('result = '.$result) if ($formula);
     return $result;
 }
 
@@ -2988,6 +2990,8 @@
 
     function celledit(cellname,cellformula) {
         var edit_text = '';
+        // cellformula may contain less-than and greater-than symbols, so
+        // we need to escape them?  
         edit_text +='<html><head><title>Cell Edit Window</title></head><body>';
         edit_text += '<form name="editwinform">';
         edit_text += '<center><h3>Cell '+cellname+'</h3>';