]> Sergey Matveev's repositories - public-inbox.git/commitdiff
feeds use XHTML to avoid tag soup
authorEric Wong <e@80x24.org>
Sun, 27 Apr 2014 06:21:57 +0000 (06:21 +0000)
committerEric Wong <e@80x24.org>
Sun, 27 Apr 2014 06:21:57 +0000 (06:21 +0000)
This should work in most browsers, lets find out!

lib/PublicInbox/Feed.pm
lib/PublicInbox/Hval.pm

index 2dc3940ff7e4fc3bd591f5501eb40f53792fb112..bddba912a5cc720a9989d830a72da803b708cada 100644 (file)
@@ -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),
        );
index 09ae2676a2551ac1501f63574b5604404aa8b845..1a83cf10a54561f698f45a6671d6ed1f99734548 100644 (file)
@@ -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 = (
+       '"' => '&#34;',
+       '&' => '&#38;',
+       "'" => '&#39;',
+       '<' => '&lt;',
+       '>' => '&gt;',
+);
+
+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})) }