From 3b395d58206174e283f62ac5ca3a382c9d375a02 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 30 Mar 2017 14:34:48 +0200 Subject: [PATCH] common: decode utf8 path request Support unicode input. --- charset.plp | 5 ++--- common.inc.plp | 3 ++- source.plp | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/charset.plp b/charset.plp index 4c01b78..fcd647d 100644 --- a/charset.plp +++ b/charset.plp @@ -24,7 +24,6 @@ my $glyphs = Shiar_Sheet::FormatChar->new; my @nibble = (0..9, 'A'..'F'); my $nibsize = 1; -use Encode qw(decode resolve_alias); # generate character table(s) # (~16x faster than decoding in loop; # substr strings is twice as fast as splitting to an array) @@ -71,7 +70,7 @@ my @request = map { @nibble = (map { $_.0, $_.8 } 0 .. 7); $nibsize = 8; } - elsif ($row{set} = resolve_alias($input)) { + elsif ($row{set} = Encode::resolve_alias($input)) { if ($row{set} eq 'Internal') { $row{table} = ' ' x ($endpoint < 255 ? 640 : 8192); $row{set} = 'Unicode BMP'; @@ -85,7 +84,7 @@ my @request = map { or printf "

Table data could not be read: %s.

\n", $@ || $!; } else { - $row{table} = decode($row{set}, pack 'C*', $row{offset} .. $endpoint); + $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $endpoint); } } else { diff --git a/common.inc.plp b/common.inc.plp index 0a010d2..81f91b5 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -8,6 +8,7 @@ use open ':std' => ':utf8'; use File::stat 'stat'; use HTTP::Date; +use Encode qw( decode_utf8 ); $PLP::ERROR = sub { my ($text, $html) = @_; @@ -23,7 +24,7 @@ BEGIN { # user request our $Dev = $ENV{HTTP_HOST} =~ /\bdev\./; our ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; -our $Request = $ENV{PATH_INFO} =~ s{^/}{}r; +our $Request = decode_utf8($ENV{PATH_INFO} =~ s{^/}{}r); our $style; our $showkeys = !exists $get{keys} ? undef : diff --git a/source.plp b/source.plp index 38af1fa..56193fb 100644 --- a/source.plp +++ b/source.plp @@ -67,7 +67,6 @@ else { } -r $source or die "Requested file not found\n"; - require Encode; if (eval { require Text::VimColor and Text::VimColor->VERSION(0.12) }) { delete $Text::VimColor::SYNTAX_TYPE{Underlined}; my %TYPETAG = ( @@ -84,7 +83,7 @@ else { say '
';
 		foreach (@$parsed) {
 			my ($type, $contents) = @{$_};
-			$contents = Encode::decode_utf8($contents);
+			$contents = decode_utf8($contents);
 			my $tag = $type && ($TYPETAG{$type} || 'span');
 			my $arg = '';
 			print "<$tag$arg class=\"sy-\l$type\">" if $tag;
@@ -109,7 +108,7 @@ else {
 	}
 	else {
 		say '
';
-		print EscapeHTML(Encode::decode_utf8(ReadFile($source)));
+		print EscapeHTML(decode_utf8(ReadFile($source)));
 		say '
'; } -- 2.30.0