]> Sergey Matveev's repositories - public-inbox.git/commitdiff
fix quoted URL generation in feeds
authorEric Wong <e@80x24.org>
Tue, 22 Apr 2014 09:24:45 +0000 (09:24 +0000)
committerEric Wong <e@80x24.org>
Tue, 22 Apr 2014 09:32:47 +0000 (09:32 +0000)
While we're at it, make sure strange characters are escaped properly
in Message-IDs.  We'll need tests for all this behavior.

Documentation/design_www.txt
TODO [new file with mode: 0644]
lib/PublicInbox/Feed.pm
public-inbox.cgi

index 226a22c9704b427ddea9620a27be9a6888043923..50c9731721d4c97ac72ce29e147c922305a7acbc 100644 (file)
@@ -13,6 +13,9 @@ URL naming
 /$LISTNAME/f/$MESSAGE_ID                        -> 301 to .html version
 /$LISTNAME/f/$MESSAGE_ID.txt                    -> 301 to m/$MESSAGE_ID.txt
 
 /$LISTNAME/f/$MESSAGE_ID                        -> 301 to .html version
 /$LISTNAME/f/$MESSAGE_ID.txt                    -> 301 to m/$MESSAGE_ID.txt
 
+FIXME: we must refactor/cleanup/add tests for most of our CGI before
+adding more endpoints and features.
+
 Maybe TODO (these might be expensive)
 -------------------------------------
 /$LISTNAME/t/$MESSAGE_ID.html                   -> HTML content of thread
 Maybe TODO (these might be expensive)
 -------------------------------------
 /$LISTNAME/t/$MESSAGE_ID.html                   -> HTML content of thread
diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..76020a7
--- /dev/null
+++ b/TODO
@@ -0,0 +1 @@
+* header -> HTML/XML sanitization
index 3fc3775ba454fad5019f6416f1dbd66aae3769c1..93ee80bbef27b51b88099889c416dc36798dff6a 100644 (file)
@@ -262,11 +262,13 @@ sub add_to_feed {
        my $midurl = $feed_opts->{midurl} || 'http://example.com/m/';
        my $fullurl = $feed_opts->{fullurl} || 'http://example.com/f/';
 
        my $midurl = $feed_opts->{midurl} || 'http://example.com/m/';
        my $fullurl = $feed_opts->{fullurl} || 'http://example.com/f/';
 
-       my $content = PublicInbox::View->as_feed_entry($mime, $fullurl);
-       defined($content) or return 0;
-
        my $mid = utf8_header($mime, "Message-ID") or return 0;
        my $mid = utf8_header($mime, "Message-ID") or return 0;
-       $mid =~ s/\A<//; $mid =~ s/>\z//;
+       # FIXME: refactor
+       my (undef, $href) = PublicInbox::View::trim_message_id($mid);
+
+       my $content = PublicInbox::View->as_feed_entry($mime,
+                                                       "$fullurl$href.html");
+       defined($content) or return 0;
 
        my $subject = utf8_header($mime, "Subject") || "";
        length($subject) or return 0;
 
        my $subject = utf8_header($mime, "Subject") || "";
        length($subject) or return 0;
@@ -279,7 +281,6 @@ sub add_to_feed {
        my $email = $from[0]->address;
        defined $email or $email = "";
 
        my $email = $from[0]->address;
        defined $email or $email = "";
 
-       my $url = $midurl . uri_escape($mid);
        my $date = utf8_header($mime, "Date");
        $date or return 0;
        $date = feed_date($date) or return 0;
        my $date = utf8_header($mime, "Date");
        $date or return 0;
        $date = feed_date($date) or return 0;
@@ -288,7 +289,7 @@ sub add_to_feed {
                title => $subject,
                updated => $date,
                content => { type => "html", content => $content },
                title => $subject,
                updated => $date,
                content => { type => "html", content => $content },
-               link => $url,
+               link => $midurl . $href,
                id => $add,
        );
        1;
                id => $add,
        );
        1;
@@ -303,7 +304,7 @@ sub dump_html_line {
                my $mid = utf8_header($simple, "Message-ID");
                $mid =~ s/\A<//;
                $mid =~ s/>\z//;
                my $mid = utf8_header($simple, "Message-ID");
                $mid =~ s/\A<//;
                $mid =~ s/>\z//;
-               my $url = $args->[1] . uri_escape($mid);
+               my $url = $args->[1] . xs_html(uri_escape($mid));
                my $from = utf8_header($simple, "From");
                my @from = Email::Address->parse($from);
                $from = $from[0]->name;
                my $from = utf8_header($simple, "From");
                my @from = Email::Address->parse($from);
                $from = $from[0]->name;
index 33313bf55dd2b549bacd14413874e08e0701e87d..b9b484be38b5eb584892fcdb3e3670f4b38e7cb0 100755 (executable)
@@ -167,8 +167,9 @@ sub get_mid_html {
        my $x = mid2blob($ctx);
        return r404() unless $x;
 
        my $x = mid2blob($ctx);
        return r404() unless $x;
 
-       my $pfx = "../f/" . uri_escape($ctx->{mid}) . ".html";
        require PublicInbox::View;
        require PublicInbox::View;
+       my $mid_href = PublicInbox::View::ascii_html(uri_escape($ctx->{mid}));
+       my $pfx = "../f/$mid_href.html";
        require Email::MIME;
        [ "200 OK", {'Content-Type' => 'text/html'},
                PublicInbox::View->as_html(Email::MIME->new($$x), $pfx)];
        require Email::MIME;
        [ "200 OK", {'Content-Type' => 'text/html'},
                PublicInbox::View->as_html(Email::MIME->new($$x), $pfx)];