Skip to content

Commit eabd69e

Browse files
authored
Merge pull request #38 from timgimyee/rss-guid
Check "permaLink" in id()
2 parents a657bad + e84712a commit eabd69e

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

lib/XML/Feed/Entry/Format/RSS.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ sub id {
137137
if (@_) {
138138
$item->{guid} = $_[0];
139139
} else {
140-
$item->{guid} // $item->{link};
140+
$item->{guid} // $item->{permaLink} // $item->{link};
141141
}
142142
}
143143

t/28-rss-guid.t

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use strict;
2+
use warnings;
3+
use Test::More;
4+
5+
use XML::Feed;
6+
7+
my $feed = XML::Feed->parse('t/samples/rss-guid.xml');
8+
9+
for my $item ($feed->items) {
10+
my $re = $item->category;
11+
my $desc = $item->summary->body;
12+
like($item->id, qr/$re/, $desc);
13+
}
14+
15+
done_testing();
16+
17+
__DATA__

t/samples/rss-guid.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<rss version="2.0" xmlns:xhtml="http://www.w3.org/1999/xhtml">
3+
<channel>
4+
<title>First Weblog</title>
5+
<link>http://localhost/weblog/</link>
6+
<description>This is a test weblog.</description>
7+
<language>en-us</language>
8+
<copyright>Copyright 2004</copyright>
9+
<lastBuildDate>Sat, 29 May 2004 23:39:25 -0800</lastBuildDate>
10+
<pubDate>Sat, 29 May 2004 23:39:57 -0800</pubDate>
11+
<generator>http://www.movabletype.org/?v=3.0D</generator>
12+
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
13+
<webMaster>Melody</webMaster>
14+
15+
<item>
16+
<title>Entry Two - link and id differ, isPermaLink="true"</title>
17+
<description><![CDATA[Found id from "permaLink": <guid isPermaLink="true">]]></description>
18+
<xhtml:body><![CDATA[<p>Hello!</p>]]></xhtml:body>
19+
<link>http://localhost/weblog/2004/05/pets.html</link>
20+
<author>Melody</author>
21+
<guid isPermaLink="true">http://localhost/weblog/2004/05/cats.html</guid>
22+
<category>cats</category>
23+
<pubDate>Sat, 29 May 2004 23:39:25 -0800</pubDate>
24+
</item>
25+
26+
<item>
27+
<title>Entry Two - link and id differ, isPermaLink="false"</title>
28+
<description><![CDATA[Found id from "guid": <guid isPermaLink="false">]]></description>
29+
<xhtml:body><![CDATA[<p>Hello!</p>]]></xhtml:body>
30+
<link>http://localhost/weblog/2004/05/pets.html</link>
31+
<author>Melody</author>
32+
<guid isPermaLink="false">http://localhost/weblog/2004/05/dogs.html</guid>
33+
<category>dogs</category>
34+
<pubDate>Sat, 29 May 2004 23:39:25 -0800</pubDate>
35+
</item>
36+
37+
<item>
38+
<title>Entry Two - link and no id</title>
39+
<description><![CDATA[Found id from "link": no <guid>]]></description>
40+
<xhtml:body><![CDATA[<p>Hello!</p>]]></xhtml:body>
41+
<link>http://localhost/weblog/2004/05/pets.html</link>
42+
<author>Melody</author>
43+
<category>pets</category>
44+
<pubDate>Sat, 29 May 2004 23:39:25 -0800</pubDate>
45+
</item>
46+
47+
</channel>
48+
</rss>

0 commit comments

Comments
 (0)