From 23de6ffe65656114bfdbdb6649dbbfcdffaf5a5c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 27 Apr 2014 06:21:57 +0000 Subject: feeds use XHTML to avoid tag soup This should work in most browsers, lets find out! --- lib/PublicInbox/Feed.pm | 2 +- lib/PublicInbox/Hval.pm | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index 2dc3940f..bddba912 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -286,7 +286,7 @@ sub add_to_feed { author => { name => $name, email => $email }, title => $subject, updated => $date, - content => { type => "html", content => $content }, + content => { type => 'xhtml', content => $content }, link => $midurl . $href, id => 'urn:uuid:' . join('-', @uuid5), ); diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index 09ae2676..1a83cf10 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -7,7 +7,6 @@ use strict; use warnings; use fields qw(raw); use Encode qw(find_encoding); -use CGI qw(escapeHTML); use URI::Escape qw(uri_escape); my $enc_ascii = find_encoding('us-ascii'); @@ -38,7 +37,19 @@ sub new_oneline { $class->new($raw); } -sub ascii_html { $enc_ascii->encode(escapeHTML($_[0]), Encode::HTMLCREF) } +my %xhtml_map = ( + '"' => '"', + '&' => '&', + "'" => ''', + '<' => '<', + '>' => '>', +); + +sub ascii_html { + my ($s) = @_; + $s =~ s/([<>&'"])/$xhtml_map{$1}/ge; + $enc_ascii->encode($s, Encode::HTMLCREF); +} sub as_html { ascii_html($_[0]->{raw}) } sub as_href { ascii_html(uri_escape($_[0]->{raw})) } -- cgit v1.2.3-24-ge0c7