Update xml:base parsing in RSS
Simon Wistow [Thu, 23 Oct 2008 23:30:32 +0000 (23:30 +0000)]
lib/XML/Feed/RSS.pm
t/11-xml-base-rss.t
t/samples/base_rss.xml

index 8c5b80b..d1911fd 100644 (file)
@@ -208,19 +208,28 @@ sub summary {
 sub content {
     my $item = shift->{entry};
     if (@_) {
+        my $c;
+        if (ref($_[0]) eq 'XML::Feed::Content') {
+            if (defined $_[0]->base) {
+                $c = { 'content' => $_[0]->body, 'xml:base' => $_[0]->base };
+            } else {
+                $c = $_[0]->body;
+            }
+        } else {
+            $c = $_[0];
+        }
         my $c = ref($_[0]) eq 'XML::Feed::Content' ? $_[0]->body : $_[0];
         $item->{content}{encoded} = $c;
     } else {
-        my $description = $item->{description};
         my $base;
-        if ('HASH' eq ref($description)) {
-            $base = $description->{'xml:base'};
-            $description = $description->{content};
-        }
         my $body =
             $item->{content}{encoded} ||
             $item->{'http://www.w3.org/1999/xhtml'}{body} ||
-            $description;
+            $item->{description};
+        if ('HASH' eq ref($body)) {
+            $base = $body->{'xml:base'};
+            $body = $body->{content};
+        }
         XML::Feed::Content->wrap({ type => 'text/html', body => $body, base => $base });
     }
 }
index 6efcdcb..0da6621 100644 (file)
@@ -1,11 +1,18 @@
 # $Id: $
 
 use strict;
-use Test::More tests => 13;
+use Test::More;
 use XML::Feed;
+use XML::RSS;
 
+if ($XML::RSS::VERSION <= 1.36) {
+    plan skip_all => "Version of XML::RSS is too old to do xml:base";
+} else {
+    plan tests => 13;
+}
 
 my $feed    = XML::Feed->parse('t/samples/base_rss.xml');
+
 my ($entry) = $feed->entries;
 my $content = $entry->content;
 is($feed->base,    "http://example.org/",                         "Got feed base");
index 80f4db2..bd07313 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8" ?>
 <rss version="2.0" xml:base="http://example.org/">
 <channel>
 <title>Sample Feed</title>