From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS12876 163.172.0.0/16 X-Spam-Status: No, score=-0.6 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (torrelay6.tomhek.net [163.172.38.175]) by dcvr.yhbt.net (Postfix) with ESMTP id 935A51F859 for ; Sun, 14 Aug 2016 10:21:35 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 11/11] XML val checks Date: Sun, 14 Aug 2016 10:21:17 +0000 Message-Id: <20160814102117.11456-11-e@80x24.org> In-Reply-To: <20160814102117.11456-1-e@80x24.org> References: <20160814102117.11456-1-e@80x24.org> List-Id: --- lib/PublicInbox/Hval.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index b354aa4..93253ed 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -51,10 +51,22 @@ my %xhtml_map = ( '>' => '>', ); +$xhtml_map{chr($_)} = sprintf('\\x%02x', $_) for (0..31); +$xhtml_map{"\x00"} = '\\0'; # NUL +$xhtml_map{"\x07"} = '\\a'; # bell +$xhtml_map{"\x08"} = '\\b'; # backspace +$xhtml_map{"\x09"} = "\t"; # obvious +$xhtml_map{"\x0a"} = "\n"; # obvious +$xhtml_map{"\x0b"} = '\\v'; # vertical tab +$xhtml_map{"\x0c"} = '\\f'; # form feed +$xhtml_map{"\x0d"} = '\\r'; # carriage ret +$xhtml_map{"\x1b"} = '^['; # ASCII escape (mutt seems to do this) +$xhtml_map{"\x7f"} = '\\x7f'; # DEL + sub ascii_html { my ($s) = @_; $s =~ s/\r\n/\n/sg; # fixup bad line endings - $s =~ s/([<>&'"])/$xhtml_map{$1}/ge; + $s =~ s/([<>&'"\x7f\x00-\x1f])/$xhtml_map{$1}/sge; $enc_ascii->encode($s, Encode::HTMLCREF); } -- EW