Skip Menu |
 

This queue is for tickets about the XML-RSS CPAN distribution.

Report information
The Basics
Id: 76185
Status: open
Priority: 0/
Queue: XML-RSS

People
Owner: Nobody in particular
Requestors: STUIFZAND [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.49
Fixed in: (no value)



Subject: Parsing and generating RSS feed removed atom ns and links
Download (untitled) / with headers
text/plain 243b
I included a test file that shows that a feed parsed from a file will neglect to output the 'atom' namespace declaration and the two 'atom:link's from the input. I would expect this namespace and the two links to be recreated in the output.
Subject: xml-rss-atom.t
Download xml-rss-atom.t
text/x-perl 820b
use Test::More tests => 1; use Test::Differences; use XML::RSS; my $rss = XML::RSS->new(); my $input = <<"INPUT"; <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" > <channel> <title>Example.com feed</title> <link>http://example.com/</link> <description></description> <atom:link href="http://pubsubhubbub.example.com" rel="hub"/> <atom:link href="http://example.com/feed/rss.xml" rel="self" type="application/rss+xml"/> </channel> </rss> INPUT $rss->parse($input); eq_or_diff($rss->as_string . "\n", $input);
Download (untitled) / with headers
text/plain 772b
On Sat Mar 31 10:13:23 2012, STUIFZAND wrote: Show quoted text
> > I included a test file that shows that a feed parsed from a file will > neglect to output the 'atom' namespace declaration and the two > 'atom:link's from the input. > > I would expect this namespace and the two links to be recreated in the > output.
Well, it seems that this is indeed a problem. Thanks for reporting it. Maybe I'll get to fix it, but if you can volunteer to write a patch instead, that would be appreciated. A few notes about the test: 1. It needs to patch a test file, preferably t/test-generated-items.t (or a new test file). 2. Please don't test for exact output, but rather test for substrings or verify that the XML contains the atom links using a regular expression. Regards, -- Shlomi Fish
From: toapole [...] gmail.com
Download (untitled) / with headers
text/plain 366b
On Sat Mar 31 10:13:23 2012, STUIFZAND wrote: Show quoted text
> > I included a test file that shows that a feed parsed from a file will > neglect to output the 'atom' namespace declaration and the two > 'atom:link's from the input. > > I would expect this namespace and the two links to be recreated in the > output.
I have same problem with generating custom namespace elements.
From: peter [...] stuifzand.com
Download (untitled) / with headers
text/plain 1.5k
On Thu Apr 05 07:21:44 2012, SHLOMIF wrote: Show quoted text
> On Sat Mar 31 10:13:23 2012, STUIFZAND wrote:
> > > > I included a test file that shows that a feed parsed from a file will > > neglect to output the 'atom' namespace declaration and the two > > 'atom:link's from the input. > > > > I would expect this namespace and the two links to be recreated in the > > output.
> > Well, it seems that this is indeed a problem. Thanks for reporting it. > Maybe I'll get to fix it, but if you can volunteer to write a patch > instead, that would be appreciated. > > A few notes about the test: > > 1. It needs to patch a test file, preferably t/test-generated-items.t > (or a new test file). > > 2. Please don't test for exact output, but rather test for substrings or > verify that the XML contains the atom links using a regular expression. > > Regards, > > -- Shlomi Fish
Tonight I've been searching for the exact problem. It seems that the 'atom:link' element isn't gathered into the 'channel' structure. If it is available in the channel then it will be generated in the output. So the problem is on the parse side of code. Two problems, actually. Problem 1: For RSS 2.0 the namespaces aren't set. In this case the 'atom' namespace/module isn't generated, only defaults. Problem 2: If there is more than one "atom:link", but only one can be set. I'm not sure how to solve this problem in the current structure of the code. I attached a patch that provides a possible fix for both problem. This way it only sets atom:link for rel="self". Other atom links aren't set. But this code follows the interface for how this code is used.
Subject: atom_link.patch
Download atom_link.patch
text/x-diff 2.3k
Index: lib/XML/RSS.pm =================================================================== --- lib/XML/RSS.pm (revision 15545) +++ lib/XML/RSS.pm (working copy) @@ -940,6 +940,14 @@ croak "Malformed RSS: invalid version\n"; } + if ($attribs{version} eq '2.0') { + my @prefixes = $parser->new_ns_prefixes; + foreach my $prefix (@prefixes) { + my $uri = $parser->expand_ns_prefix($prefix); + $self->{namespaces}->{$prefix} = $uri; + } + } + # handle xml:base $self->{'xml:base'} = $attribs{'base'} if exists $attribs{'base'}; @@ -1162,6 +1170,14 @@ $self->{'channel'}->{$el} = ""; } } + elsif (($self->_current_element eq 'channel') && ($parser->namespace($el))) { + # Backward compatible atom:link + my $prefix = (grep { $el_ns eq $self->{namespaces}{$_} } keys %{$self->{namespaces}})[0]; + + if ($prefix eq 'atom' && exists $attribs{rel} && $attribs{rel} eq 'self') { + $self->{'channel'}{$prefix}{$el} = $attribs{href}; + } + } } sub _make_array { Index: t/2.0-parse-self.t =================================================================== --- t/2.0-parse-self.t (revision 15545) +++ t/2.0-parse-self.t (working copy) @@ -3,14 +3,14 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 5; use XML::RSS; my $text = <<"EOF"; <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet href="/rss/news/journalism.xsl" type="text/xsl"?> -<rss version="2.0"> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel><title>Journalism - Topix.net</title> <link>http://www.topix.net/news/journalism</link> <description>News on Journalism from Topix.net</description> @@ -20,6 +20,7 @@ <link>http://www.topix.net/</link> <url>http://www.topix.net/pics/logo4.gif</url> </image> +<atom:link rel="self" href="http://example.com/feed/rss.xml" /> <item> <title>Gannett Reportedly Mulling Tribune Bid </title> <link>http://topix.net/r/0l1Qq8DEtErajq5wDAIHZ0RavmEQ=2BIyZGBfGjcVwyQpW0DFdgUcy=2FtbxGNgMtYEdbU7ucVOR=2Bw2Bu6K4EDvt9=2B7ILEWB6Q5Zxy64f9JxkGU92am=2FLdMjb=2FCxbmfNuBQX6</link> @@ -56,6 +57,8 @@ is ($rss->{channel}->{link}, "http://www.topix.net/news/journalism", "Testing for channel link" ); + + is($rss->{channel}->{atom}->{link}, 'http://example.com/feed/rss.xml'); } {


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.