X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCGI%2FUtil.pm;h=ac7376d41ab408f7d8a087a1d3fb76c4c31a4329;hb=22d4bb9ccb8701e68f9243547d7e3a3c55f70908;hp=cb6dd8a9e206875503e9c8022bceee9e71615f07;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/CGI/Util.pm b/lib/CGI/Util.pm index cb6dd8a..ac7376d 100644 --- a/lib/CGI/Util.pm +++ b/lib/CGI/Util.pm @@ -1,13 +1,5 @@ package CGI::Util; -=pod - -=head1 NAME - -CGI::Util - various utilities - -=cut - use strict; use vars '$VERSION','@EXPORT_OK','@ISA','$EBCDIC','@A2E'; require Exporter; @@ -56,14 +48,14 @@ sub rearrange { my ($i,%pos); $i = 0; foreach (@$order) { - foreach (ref($_) eq 'ARRAY' ? @$_ : $_) { $pos{$_} = $i; } + foreach (ref($_) eq 'ARRAY' ? @$_ : $_) { $pos{lc($_)} = $i; } $i++; } my (@result,%leftover); $#result = $#$order; # preextend while (@param) { - my $key = uc(shift(@param)); + my $key = lc(shift(@param)); $key =~ s/^\-//; if (exists $pos{$key}) { $result[$pos{$key}] = shift(@param); @@ -72,7 +64,7 @@ sub rearrange { } } - push (@result,make_attributes(\%leftover)) if %leftover; + push (@result,make_attributes(\%leftover,1)) if %leftover; @result; } @@ -84,7 +76,7 @@ sub make_attributes { foreach (keys %{$attr}) { my($key) = $_; $key=~s/^\-//; # get rid of initial - if present - $key=~tr/a-z_/A-Z-/; # parameters are upper case, use dashes + $key=~tr/A-Z_/a-z-/; # parameters are lower case, use dashes my $value = $escape ? simple_escape($attr->{$_}) : $attr->{$_}; push(@att,defined($attr->{$_}) ? qq/$key="$value"/ : qq/$key/); } @@ -92,16 +84,14 @@ sub make_attributes { } sub simple_escape { - return unless defined (my $toencode = shift); - $toencode =~ s{(.)}{ - if ($1 eq '<') { '<' } - elsif ($1 eq '>') { '>' } - elsif ($1 eq '&') { '&' } - elsif ($1 eq '"') { '"' } - elsif ($1 eq "\x8b") { '‹' } - elsif ($1 eq "\x9b") { '›' } - else { $1 } - }gsex; + return unless defined(my $toencode = shift); + $toencode =~ s{&}{&}gso; + $toencode =~ s{<}{<}gso; + $toencode =~ s{>}{>}gso; + $toencode =~ s{\"}{"}gso; +# Doesn't work. Can't work. forget it. +# $toencode =~ s{\x8b}{‹}gso; +# $toencode =~ s{\x9b}{›}gso; $toencode; }