cvs commit: p5ee/App-Widget-JSApp/lib/App/Widget JSApp.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     06/02/02 12:56:28

  Modified:    App-Widget-JSApp/lib/App/Widget JSApp.pm
  Log:
  escape newlines and quotes in values passed in double quotes to the JavaScript widget
  
  Revision  Changes    Path
  1.3       +11 -3     p5ee/App-Widget-JSApp/lib/App/Widget/JSApp.pm
  
  Index: JSApp.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Widget-JSApp/lib/App/Widget/JSApp.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JSApp.pm	30 Jan 2006 22:56:44 -0000	1.2
  +++ JSApp.pm	2 Feb 2006 20:56:28 -0000	1.3
  @@ -48,7 +48,7 @@
           $js_conf = ", {";
           for (my $i = 0; $i < $#attrib; $i += 2) {
               $js_conf .= "," if ($i > 0);
  -            $js_conf .= " \"$attrib[$i]\" : \"$attrib[$i+1]\"";
  +            $js_conf .= " \"$attrib[$i]\" : \"" . $self->escape_double_quoted_value($attrib[$i+1]) . "\"";
           }
       }
   
  @@ -107,6 +107,14 @@
       return($html);
   }
   
  +sub escape_double_quoted_value {
  +    my ($self, $value) = @_;
  +    $value =~ s/"/\\"/g;
  +    $value =~ s/\r//msg;
  +    $value =~ s/\n/\\n/msg;
  +    return($value);
  +}
  +
   sub init_jsapp {
       my ($self) = @_;
       my $context = $self->{context};
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.