use EscapeHTML() from PLP v3.23
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 19 Oct 2009 02:49:03 +0000 (02:49 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 19 Oct 2009 02:51:35 +0000 (02:51 +0000)
Instead of manually defining (incorrect) quote() functions to escape HTML
attributes, use the new PLP feature EscapeHTML(), which was written for this
purpose.

cc.plp
charset.plp
digraphs.plp
source.plp
unicode.plp

diff --git a/cc.plp b/cc.plp
index 847324176763bdaa7e675c47c1fe363f48f4e688..7138c3b39cd815f06eadfae8a5b2b37b24619ba9 100644 (file)
--- a/cc.plp
+++ b/cc.plp
 <:
 my $cc = do 'cc.inc.pl';
 
 <:
 my $cc = do 'cc.inc.pl';
 
-sub quote {
-       local $_ = shift;
-       s/"/&quot;/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       return $_;
-}
-
 {
        printf '<table class="mcmap">';
        print '<col><colgroup span="26">';
 {
        printf '<table class="mcmap">';
        print '<col><colgroup span="26">';
@@ -62,12 +54,12 @@ sub quote {
                                s/North(?:ern)? /N-/g;
                                s/New /n./g;
                                s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
                                s/North(?:ern)? /N-/g;
                                s/New /n./g;
                                s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
-                               s/(\S{4}[b-df-hj-np-tv-xz])(\w{2,})/$1./g;  # abbreviate (at consonant)
-                               $_ = quote($_);
+                               s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
+                               $_ = EscapeHTML($_);
                        }
                        $name =~ s/([^,]*), (.*)/$2 $1/;
                        printf "\n".'<td class="%s" title="%s">%s',
                        }
                        $name =~ s/([^,]*), (.*)/$2 $1/;
                        printf "\n".'<td class="%s" title="%s">%s',
-                               $_ ? 'X '.$class : '', quote("$code: $name"), $_;
+                               $_ ? 'X '.$class : '', EscapeHTML("$code: $name"), $_;
                }
                print "\n";
        }
                }
                print "\n";
        }
index 29e7e23c5fb6030271b9f5dc57105aca7aed1003..66e0cc98211badf52621d4ba0281fb733d27bc21 100644 (file)
@@ -94,14 +94,6 @@ for my $cp437 (grep {$request[$_]->{set} eq 'cp437'} 0 .. $#request) {
        );
 }
 
        );
 }
 
-sub quote {
-       local $_ = shift;
-       s/"/&quot;/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       return $_;
-}
-
 my @nibble = (0..9, 'A'..'F');
 for my $row (@request) {
        printf '<div class="section"><table class="glyphs%s">', !$row->{cell} && ' charmap';
 my @nibble = (0..9, 'A'..'F');
 for my $row (@request) {
        printf '<div class="section"><table class="glyphs%s">', !$row->{cell} && ' charmap';
@@ -138,14 +130,14 @@ for my $row (@request) {
                        }
                        my ($codepoint, $name, $prop, $script, $string) = @$info;
 
                        }
                        my ($codepoint, $name, $prop, $script, $string) = @$info;
 
-                       $glyph = quote($string || $glyph);
+                       $glyph = EscapeHTML($string || $glyph);
                        my $desc = sprintf 'U+%04X%s', $codepoint, $name && " ($name)";
                        my @class = ('X', grep {$_} $prop, $script);
 
                        $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
 
                        printf "\n".'<td class="%s" title="%s">%s',
                        my $desc = sprintf 'U+%04X%s', $codepoint, $name && " ($name)";
                        my @class = ('X', grep {$_} $prop, $script);
 
                        $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
 
                        printf "\n".'<td class="%s" title="%s">%s',
-                               join(' ', @class), quote($desc), $glyph;
+                               join(' ', @class), EscapeHTML($desc), $glyph;
                }
                print "\n";
        }
                }
                print "\n";
        }
index 5192c250d9a2a9f0206f6ed74d59d7b87b121a91..5c3bf078c8526631e191a14206121faff33e105b 100644 (file)
@@ -23,14 +23,6 @@ are available as <a href="/digraphs.vim">ex commands</a>.</p>
 <:
 my $di = do 'digraphs.inc.pl';
 
 <:
 my $di = do 'digraphs.inc.pl';
 
-sub quote {
-       local $_ = shift;
-       s/"/&quot;/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       return $_;
-}
-
 my @chars = (
        [qw{! " % ' ( ) * + , - . /}],
        ['0'..'9'], [qw{: ; < = > ?}],
 my @chars = (
        [qw{! " % ' ( ) * + , - . /}],
        ['0'..'9'], [qw{: ; < = > ?}],
@@ -44,13 +36,13 @@ print qq'<colgroup span="$_">' for map {scalar @$_} @chars2;
 print "</colgroup><col>\n";
 for my $section (qw{thead tfoot}) {
        print "<$section><tr><th>↳";
 print "</colgroup><col>\n";
 for my $section (qw{thead tfoot}) {
        print "<$section><tr><th>↳";
-       print '<th>', quote($_) for map {@$_} @chars2;
+       print '<th>', EscapeHTML($_) for map {@$_} @chars2;
        print "<th>&nbsp;\n";
 }
 for my $c1group (@chars) {
        print '<tbody>';
        for my $c1 (@$c1group) {
        print "<th>&nbsp;\n";
 }
 for my $c1group (@chars) {
        print '<tbody>';
        for my $c1 (@$c1group) {
-               print '<tr><th>', quote($c1);
+               print '<tr><th>', EscapeHTML($c1);
                for my $c2 (map {@$_} @chars2) {
                        my $mnem = $c1 . $c2;
                        if (not defined $di->{$mnem}) {
                for my $c2 (map {@$_} @chars2) {
                        my $mnem = $c1 . $c2;
                        if (not defined $di->{$mnem}) {
@@ -58,7 +50,7 @@ for my $c1group (@chars) {
                                next;
                        }
                        if (ref $di->{$mnem} ne 'ARRAY') {
                                next;
                        }
                        if (ref $di->{$mnem} ne 'ARRAY') {
-                               printf '<td class="X Xr" title="%s">', quote($mnem);
+                               printf '<td class="X Xr" title="%s">', EscapeHTML($mnem);
                                next;
                        }
                        my ($codepoint, $name, $prop, $script, $string) = @{ $di->{$mnem} };
                                next;
                        }
                        my ($codepoint, $name, $prop, $script, $string) = @{ $di->{$mnem} };
@@ -68,13 +60,13 @@ for my $c1group (@chars) {
                        my $desc = $mnem . ($name && " ($name)");
                        my @class = ('X', grep {$_} $prop, $script);
 
                        my $desc = $mnem . ($name && " ($name)");
                        my @class = ('X', grep {$_} $prop, $script);
 
-                       $glyph = quote($glyph);
+                       $glyph = EscapeHTML($glyph);
                        $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
 
                        printf "\n".'<td class="%s" title="%s">%s',
                        $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
 
                        printf "\n".'<td class="%s" title="%s">%s',
-                               join(' ', @class), quote($desc), $glyph;
+                               join(' ', @class), EscapeHTML($desc), $glyph;
                }
                }
-               print "\n<th>", quote($c1), "\n";
+               print "\n<th>", EscapeHTML($c1), "\n";
        }
 }
 print "</table>\n";
        }
 }
 print "</table>\n";
index 295f9e068ec295cedda2577dd306f4b91ec5d831..7640ae00b1210e2f08de4a12f0068af018a22c20 100644 (file)
@@ -24,7 +24,7 @@ if (not $source) {
        print '<ul>'."\n";
        for (glob '*.plp') {
                chomp;
        print '<ul>'."\n";
        for (glob '*.plp') {
                chomp;
-               printf '<li><a href="/source/%s">%1$s</a></li>'."\n", Entity($_);
+               printf '<li><a href="/source/%s">%1$s</a></li>'."\n", EscapeHTML($_);
        }
        print "</ul>\n\n";
 }
        }
        print "</ul>\n\n";
 }
index ac631704979da9c6db8303200b04b71a467f708b..959b121780cc9e31a3c21b9098a4a7b569cb8551 100644 (file)
@@ -24,14 +24,6 @@ my $diinfo = do 'digraphs.inc.pl';
 my %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
        sort { length $a <=> length $b } keys %$diinfo;
 
 my %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
        sort { length $a <=> length $b } keys %$diinfo;
 
-sub quote {
-       local $_ = shift;
-       s/"/&quot;/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       return $_;
-}
-
 sub glyph_table {
        my ($digraphs) = @_;
 
 sub glyph_table {
        my ($digraphs) = @_;
 
@@ -109,8 +101,8 @@ sub glyph_table {
                        defined $name  ? qq{ title="$name"}  : '',
                        @class ? sprintf(' class="%s"', join ' ', @class) : '',
                        $colspan > 1 && qq{ colspan="$colspan"},
                        defined $name  ? qq{ title="$name"}  : '',
                        @class ? sprintf(' class="%s"', join ' ', @class) : '',
                        $colspan > 1 && qq{ colspan="$colspan"},
-                       $cell eq '' ? '&nbsp;' : quote($cell),
-                       defined $code ? sprintf(' <small class="digraph">%s</small>', quote($code))
+                       $cell eq '' ? '&nbsp;' : EscapeHTML($cell),
+                       defined $code ? sprintf(' <small class="digraph">%s</small>', EscapeHTML($code))
                                : length($cell) == 1 && $cell !~ /[a-z]/
                                        ? sprintf(' <small class="%s">%04X</small>', 'value', ord $cell)
                                        : '',
                                : length($cell) == 1 && $cell !~ /[a-z]/
                                        ? sprintf(' <small class="%s">%04X</small>', 'value', ord $cell)
                                        : '',