[system] / trunk / webwork2 / lib / WeBWorK / DB / WW.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/DB/WW.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 425 Revision 426
392# $string - string to decode 392# $string - string to decode
393sub decode($) { 393sub decode($) {
394 my $string = shift; 394 my $string = shift;
395 return unless defined $string and $string; 395 return unless defined $string and $string;
396 my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g; 396 my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g;
397 $hash{$_} =~ s/\\(.)/$1/ foreach (keys %hash); # unescape anything 397 $hash{$_} =~ s/\\(.)/$1/g foreach (keys %hash); # unescape anything
398 return %hash; 398 return %hash;
399} 399}
400 400
401# encode(%hash) - encodes a hash as a quasi-URL-encoded string for insertion 401# encode(%hash) - encodes a hash as a quasi-URL-encoded string for insertion
402# into a hash-based webwork database. Escapes & and = in 402# into a hash-based webwork database. Escapes & and = in
405sub encode(%) { 405sub encode(%) {
406 my %hash = @_; 406 my %hash = @_;
407 my $string; 407 my $string;
408 foreach (keys %hash) { 408 foreach (keys %hash) {
409 $hash{$_} = "" unless defined $hash{$_}; # promote undef to "" 409 $hash{$_} = "" unless defined $hash{$_}; # promote undef to ""
410 $hash{$_} =~ s/(=|&)/\\$1/; # escape & and = 410 $hash{$_} =~ s/(=|&)/\\$1/g; # escape & and =
411 $string .= "$_=$hash{$_}&"; 411 $string .= "$_=$hash{$_}&";
412 } 412 }
413 chop $string if $string; # remove final '&' from string for old code :p 413 chop $string if $string; # remove final '&' from string for old code :p
414 return $string; 414 return $string;
415} 415}

Legend:
Removed from v.425  
changed lines
  Added in v.426

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9