diff options
author | Eric Wong <e@80x24.org> | 2016-08-14 10:21:17 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-08-14 10:44:34 +0000 |
commit | 1d0ce406b75fc174bee51e77efe5f10c61fb6098 (patch) | |
tree | e057ad98a50511815c56e56c1fda2bf8697c2a82 /lib/PublicInbox/Hval.pm | |
parent | 43bd7b193a936c8368ba5808c1d693c639f25933 (diff) | |
download | public-inbox-1d0ce406b75fc174bee51e77efe5f10c61fb6098.tar.gz |
I've seen 0x1b (\e) in at least one message and some other possibly non-printable chars. In any case, make sure they're valid XML with us-ascii encoding as far as xmlstarlet(1) thinks so.
Diffstat (limited to 'lib/PublicInbox/Hval.pm')
-rw-r--r-- | lib/PublicInbox/Hval.pm | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index 652aef3d..f2620737 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -52,10 +52,24 @@ my %xhtml_map = ( '>' => '>', ); +$xhtml_map{chr($_)} = sprintf('\\x%02x', $_) for (0..31); +# some of these overrides are standard C escapes so they're +# easy-to-understand when rendered. +$xhtml_map{"\x00"} = '\\0'; # NUL +$xhtml_map{"\x07"} = '\\a'; # bell +$xhtml_map{"\x08"} = '\\b'; # backspace +$xhtml_map{"\x09"} = "\t"; # obvious to show as-is +$xhtml_map{"\x0a"} = "\n"; # obvious to show as-is +$xhtml_map{"\x0b"} = '\\v'; # vertical tab +$xhtml_map{"\x0c"} = '\\f'; # form feed +$xhtml_map{"\x0d"} = '\\r'; # carriage ret (not preceding \n) +$xhtml_map{"\x1b"} = '^['; # ASCII escape (mutt seems to escape this way) +$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); } |