[livejournal] r10283: Atom spec states that link tags with no ...
Committer: ahassan
Atom spec states that link tags with no explicit rel attribute are to be treated as rel="alternate". So fix that, and add test.http://rt.livejournal.org/Ticket/Display.html?id=1086
U trunk/cgi-bin/parsefeed.pl A trunk/t/parsefeed-atom-link.t
Modified: trunk/cgi-bin/parsefeed.pl
===================================================================
--- trunk/cgi-bin/parsefeed.pl 2007-02-02 04:40:46 UTC (rev 10282)
+++ trunk/cgi-bin/parsefeed.pl 2007-02-02 05:16:20 UTC (rev 10283)
@@ -277,7 +277,8 @@
if ($tag eq 'link') {
# ignore links with rel= anything but alternate
- unless ($_{'rel'} eq 'alternate') {
+ # and treat links as rel=alternate if not explicit
+ unless ($_{'rel'} eq 'alternate' || !$_{'rel'}) {
swallow();
last TAGS;
}
Added: trunk/t/parsefeed-atom-link.t
===================================================================
--- trunk/t/parsefeed-atom-link.t 2007-02-02 04:40:46 UTC (rev 10282)
+++ trunk/t/parsefeed-atom-link.t 2007-02-02 05:16:20 UTC (rev 10283)
@@ -0,0 +1,41 @@
+# -*-perl-*-
+use strict;
+use Test::More 'no_plan';
+use lib "$ENV{LJHOME}/cgi-bin";
+require "parsefeed.pl";
+require 'ljlib.pl';
+
+my $testfeed = sub {
+ my $link_content = shift;
+
+ my $contents = qq {
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <id>testing:atom:feed</id>
+ <title>test atom feed</title>
+ <author><name>testing</name></author>
+ <link rel="alternate" type="text/html" href="$LJ::SITEROOT" />
+ <link rel="self" type="text/xml" href="$LJ::SITEROOT" />
+ <updated>2007-01-08T23:40:33Z</updated>
+ <entry>
+ <id>testing:atom:feed:entry</id>
+ $link_content
+ <title>default userpic</title>
+ <updated>2006-09-14T07:39:07Z</updated>
+ <content type="html">content content content</content>
+ </entry>
+</feed>
+};
+
+ my ($feed, $error) = LJ::ParseFeed::parse_feed($contents);
+ my $item = $feed->{'items'}->[0];
+ return $item->{'link'};
+};
+
+is($testfeed->("<link rel=\"alternate\" type=\"text/html\" href=\"$LJ::SITEROOT\" />"),
+ $LJ::SITEROOT, "rel=alternate is fine");
+
+is($testfeed->("<link type=\"text/html\" href=\"$LJ::SITEROOT\" />"),
+ $LJ::SITEROOT, "no explicit rel attribute is also fine");
+
+ok(!$testfeed->("<link rel=\"bananas\" type=\"text/html\" href=\"$LJ::SITEROOT\" />"),
+ "rel that isn't 'alternate' not okay");
Property changes on: trunk/t/parsefeed-atom-link.t
___________________________________________________________________
Name: svn:executable
+ *
