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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 25 Jun 2003 15:33:49 -0000


matthew		Wed Jun 25 11:33:49 2003 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm 
  Log:
  Bug 1635: Handle ' and " cleanly.  
  &html_editable_cell:By default &HTML::Entities::encode does
  not encode single quotes.  By passing our own list of things to encode 
  (or in this case, not to encode) we take care of all sorts of issues.
  
  
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.17 loncom/interface/spreadsheet/Spreadsheet.pm:1.18
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.17	Mon Jun 23 15:58:18 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Wed Jun 25 11:33:49 2003
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.17 2003/06/23 19:58:18 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.18 2003/06/25 15:33:49 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1202,13 +1202,15 @@
         $value = &HTML::Entities::encode($value) if ($value !~/ /);
     }
     return $value if (! $allowed);
-    # Make the formula safe for outputting
-    $formula =~ s/\'/\"/g;
+    #
     # The formula will be parsed by the browser twice before being 
-    # displayed to the user for editing.
-    $formula = &HTML::Entities::encode(&HTML::Entities::encode($formula));
-    # Escape newlines so they make it into the edit window
-    $formula =~ s/\n/\\n/gs;
+    # displayed to the user for editing. 
+    #
+    # The encoding string "^A-blah" is placed in []'s inside a regexp, so 
+    # we specify the characters we want left alone by putting a '^' in front.
+    $formula = &HTML::Entities::encode($formula,"^A-z0-9 !#\$%-;=?~");
+    # Escape it again - this time the only encodable character is '&'
+    $formula =~ s/\&/\&/g;
     # Glue everything together
     $result .= "<a href=\"javascript:celledit(\'".
         $name."','".$formula."');\">".$value."</a>";