Added new (currently failing) test for the double-encoding bug.
Dave Cross [Sat, 16 Jul 2011 16:03:27 +0000 (17:03 +0100)]
MANIFEST
lib/XML/Feed/Format/Atom.pm
t/19-double3.t [new file with mode: 0644]
t/samples/rss10-double2.xml [new file with mode: 0644]

index bdbb922..b5afaa4 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -56,3 +56,6 @@ t/samples/rss20.xml
 t/samples/rss-multiple-categories.xml
 t/samples/rss-multiple-subjects.xml
 Makefile.PL
+META.json
+t/19-double3.t
+t/samples/rss10-double2.xml
index 53573f5..b0a8554 100644 (file)
@@ -200,19 +200,22 @@ sub content {
         my $orig_body;
         if (ref($_[0]) eq 'XML::Feed::Content') {
             $orig_body = $_[0]->body;
-                       if (defined $_[0]->type && defined $types{$_[0]->type}) {
-                   %param = (Body => $_[0]->body, Type => $types{$_[0]->type});
+            if (defined $_[0]->type && defined $types{$_[0]->type}) {
+                %param = (Body => $orig_body, Type => $types{$_[0]->type});
 
-                if ($param{'Type'} eq "html") {
-                    $param{'Body'} = HTML::Entities::encode_entities($param{'Body'});
+                if ($param{Type} eq 'html') {
+                    $param{Body} = HTML::Entities::encode_entities($param{Body});
                 }
-                       } else {
-                               %param = (Body => $_[0]->body);
-                       }
+            } else {
+                # %param = (Body => $_[0]->body);
+            }
             $base = $_[0]->base if defined $_[0]->base;
         } else {
-                       $orig_body = $_[0];
-            %param = (Body => $_[0]);
+            $orig_body = $_[0];
+            # %param = (Body => $_[0]);
+        }
+        if (!exists $param{Body}) {
+            $param{Body} = $orig_body;
         }
         $entry->{entry}->content(XML::Atom::Content->new(%param, Version => 1.0));
         $entry->{entry}->content->base($base) if defined $base;
diff --git a/t/19-double3.t b/t/19-double3.t
new file mode 100644 (file)
index 0000000..de369d9
--- /dev/null
@@ -0,0 +1,72 @@
+use strict;
+use warnings;
+
+use Test::More tests => 14;
+
+use XML::Feed;
+use File::Spec;
+
+
+{
+    my $rss = XML::Feed->parse(
+        File::Spec->catfile(File::Spec->curdir(), 
+            "t", "samples", "rss10-double2.xml"
+        )
+    );
+
+    # TEST
+    isa_ok($rss, 'XML::Feed::Format::RSS');
+    my $rss_entry = ($rss->entries)[0];
+
+    # TEST
+    isa_ok($rss_entry, 'XML::Feed::Entry::Format::RSS');
+
+
+    my $rss_content = $rss_entry->content;
+
+    # TEST
+    isa_ok($rss_content, 'XML::Feed::Content');
+
+    # TEST
+    is($rss_content->type, 'text/html', 'Correct content type');
+
+    # TEST
+    like($rss_content->body, qr(<|&lt;), 'Contains HTML tags');
+
+    # TEST
+    like($rss_content->body, 
+         qr{\Q<img src="http://s.ph-cdn.com/newman/gfx/news/2011/3-neuroscienti.jpg" width="300" class="articleImage" />},
+         'Contains HTML tags');
+
+    unlike($rss->as_xml, qr{&amp;lt;}, 'No double encoding');
+
+    my $atom = $rss->convert('Atom');
+
+    # TEST
+    isa_ok($atom, 'XML::Feed::Format::Atom');
+
+    my $atom_entry = ($atom->entries)[0];
+
+    # TEST
+    isa_ok($atom_entry, 'XML::Feed::Entry::Format::Atom');
+
+    my $atom_content = $atom_entry->content;
+
+    # TEST
+    isa_ok($atom_content, 'XML::Feed::Content');
+
+    # TEST
+    is($atom_content->type, 'text/html', 'Correct content type');
+
+    # TEST
+    like($atom_content->body, qr(<|&lt;), 'Contains HTML tags');
+
+    # TEST
+    like($atom_content->body, 
+        qr{\Q<img src="http://s.ph-cdn.com/newman/gfx/news/2011/3-neuroscienti.jpg" width="300" class="articleImage" />},
+        'Contains HTML tags');
+
+    diag $atom->as_xml;
+    unlike($atom->as_xml, qr{&amp;lt;}, 'No double encoding');
+}
+
diff --git a/t/samples/rss10-double2.xml b/t/samples/rss10-double2.xml
new file mode 100644 (file)
index 0000000..a2aa4c0
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">\r
+  <channel>\r
+    <title>RichardDawkins.net - All Content</title>\r
+    <description>All original and aggregated news articles, audio and videos on RichardDawkins.net</description>\r
+    <link>http://richarddawkins.net/archive/all_content/latest</link>\r
+    \r
+    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/richarddawkins" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="richarddawkins" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" />\r
+    <item>\r
+      <title>Neuroscientists uncover neural mechanisms of object recognition - - - medicalxpress.com</title>\r
+      <description>&lt;p&gt;&lt;img src="http://s.ph-cdn.com/newman/gfx/news/2011/3-neuroscienti.jpg" width="300" class="articleImage" /&gt;&lt;em&gt;Certain brain injuries can cause people to lose the ability to visually recognize objects -- for example, confusing a harmonica for a cash register. Neuroscientists from Carnegie Mellon University and Princeton University examined the brain of a person with object agnosia, a deficit in the ability to recognize objects that does not include damage to the eyes or a general loss in intelligence, and have uncovered the neural mechanisms of object recognition. The results, published by Cell Press in the July 15th issue of the journal Neuron, describe the functional neuroanatomy of object agnosia and suggest that damage to the part of the brain critical for object recognition can have a widespread impact on remote parts of the cortex. These findings will force researchers to rethink basic assumptions of visual neuroscience. Credit: Carnegie Mellon University and Princeton University&lt;/em&gt;&lt;/p&gt;\r
+\r
+&lt;p&gt;&lt;strong&gt;Certain brain injuries can cause people to lose the ability to visually recognize objects — for example, confusing a harmonica for a cash register.&lt;/strong&gt;&lt;/p&gt;\r
+\r
+&lt;p&gt;Neuroscientists from Carnegie Mellon University and Princeton University examined the brain of a person with object agnosia, a deficit in the ability to recognize objects that does not include damage to the eyes or a general loss in intelligence, and have uncovered the neural mechanisms of object recognition. The results, published by Cell Press in the July 15th issue of the journal Neuron, describe the functional neuroanatomy of object agnosia and suggest that damage to the part of the brain critical for object recognition can have a widespread impact on remote parts of the cortex.&lt;br&gt;\r
+&lt;a href="http://medicalxpress.com/news/2011-07-neuroscientists-uncover-neural-mechanisms-recognition.html#share"&gt;Read more and watch video&lt;/a&gt;&lt;/p&gt;\r
+</description>\r
+      <pubDate>Thu, 14 Jul 2011 14:36:55 +0000</pubDate>\r
+      <link>http://richarddawkins.net/videos/642152-neuroscientists-uncover-neural-mechanisms-of-object-recognition</link>\r
+      <guid>http://richarddawkins.net/videos/642152-neuroscientists-uncover-neural-mechanisms-of-object-recognition</guid>\r
+      <category>Medicine</category>\r
+    </item>\r
+  </channel>\r
+</rss>\r