From: Dave Cross Date: Sun, 11 Dec 2011 12:47:52 +0000 (+0000) Subject: Added tests for bug 73160. And code to make them pass. X-Git-Tag: RELEASE_0.48~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FXML-Feed.git;a=commitdiff_plain;h=710ed823bd555178ff6dc48b22a496aaebe25ed7 Added tests for bug 73160. And code to make them pass. --- diff --git a/MANIFEST b/MANIFEST index a8c3085..46f9e14 100644 --- a/MANIFEST +++ b/MANIFEST @@ -65,4 +65,5 @@ t/samples/rss10-double2.xml t/20-no-enclosures.t t/21-rss2-permalinks.t t/samples/rss20-p.xml - +t/22-bug73160.t +t/samples/rss10-datespaces.xml diff --git a/lib/XML/Feed/Format/RSS.pm b/lib/XML/Feed/Format/RSS.pm index 07be8a7..a147bc1 100644 --- a/lib/XML/Feed/Format/RSS.pm +++ b/lib/XML/Feed/Format/RSS.pm @@ -49,7 +49,12 @@ sub format { 'RSS ' . $_[0]->{rss}->{'version'} } ## The following elements are the same in all versions of RSS. sub title { shift->{rss}->channel('title', @_) } -sub link { shift->{rss}->channel('link', @_) } +sub link { + my $link = shift->{rss}->channel('link', @_); + $link =~ s/^\s+//; + $link =~ s/\s+$//; + return $link; +} sub description { shift->{rss}->channel('description', @_) } sub updated { shift->modified(@_) } @@ -135,8 +140,12 @@ sub modified { my $date; eval { if (my $ts = $rss->channel('pubDate')) { + $ts =~ s/^\s+//; + $ts =~ s/\s+$//; $date = DateTime::Format::Mail->parse_datetime($ts); } elsif ($ts = $rss->channel->{dc}{date}) { + $ts =~ s/^\s+//; + $ts =~ s/\s+$//; $date = DateTime::Format::W3CDTF->parse_datetime($ts); } }; @@ -191,9 +200,12 @@ sub link { ## For RSS 2.0 output from XML::RSS. Sigh. $entry->{entry}{permaLink} = $_[0]; } else { - $entry->{entry}{link} || - $entry->{entry}{permaLink} || - $entry->{entry}{guid}; + my $link = $entry->{entry}{link} || + $entry->{entry}{permaLink} || + $entry->{entry}{guid}; + $link =~ s/^\s+//; + $link =~ s/\s+$//; + } } @@ -303,9 +315,13 @@ sub issued { if (my $ts = $item->{pubDate}) { my $parser = DateTime::Format::Mail->new; $parser->loose; + $ts =~ s/^\s+//; + $ts =~ s/\s+$//; $date = $parser->parse_datetime($ts); } elsif ($ts = $item->{dc}{date} or $ts = $item->{dcterms}{date}) { - $date = DateTime::Format::W3CDTF->parse_datetime($ts); + $ts =~ s/^\s+//; + $ts =~ s/\s+$//; + $date = DateTime::Format::W3CDTF->parse_datetime($ts); } }; return $date; @@ -318,7 +334,10 @@ sub modified { $item->{dcterms}{modified} = DateTime::Format::W3CDTF->format_datetime($_[0]); } else { - if (my $ts = $item->{dcterms}{modified} || $item->{'http://www.w3.org/2005/Atom'}{updated}) { + if (my $ts = $item->{dcterms}{modified} || + $item->{'http://www.w3.org/2005/Atom'}{updated}) { + $ts =~ s/^\s+//; + $ts =~ s/\s+$//; return eval { DateTime::Format::W3CDTF->parse_datetime($ts) } || eval { XML::Atom::Util::iso2dt($ts) }; } } diff --git a/t/22-bug73160.t b/t/22-bug73160.t new file mode 100644 index 0000000..fb3f513 --- /dev/null +++ b/t/22-bug73160.t @@ -0,0 +1,25 @@ +use strict; +use warnings; + +use Test::More; +use XML::Feed; + +my $file = 't/samples/rss10-datespaces.xml'; +my $feed = XML::Feed->parse($file); +isa_ok($feed, 'XML::Feed::Format::RSS'); +ok(my $date = $feed->modified, 'Got a feed modified date'); +isa_ok($date, 'DateTime'); + +my $link = $feed->link; +unlike($link, qr[^\s], 'No spaces at start of link'); +unlike($link, qr[\s$], 'No spaces at end of link'); + +my $entry = ($feed->entries)[0]; +ok(my $iss = $entry->issued, 'Got an entry issued date'); +isa_ok($iss, 'DateTime'); + +$link = $entry->link; +unlike($link, qr[^\s], 'No spaces at start of link'); +unlike($link, qr[\s$], 'No spaces at end of link'); + +done_testing; diff --git a/t/samples/rss10-datespaces.xml b/t/samples/rss10-datespaces.xml new file mode 100644 index 0000000..7a9ee18 --- /dev/null +++ b/t/samples/rss10-datespaces.xml @@ -0,0 +1,80 @@ + + + + + Dave's Free Press + http://www.cantrell.org.uk/david/journal + the Slightly Less Bad And Wrong Blog Edition + en-us + 2011-12-06T22:36:07Z + + + + + + Oh look, more Olympic financial incompetence + http://www.cantrell.org.uk/david/journal/id/olympic-costs-yet-again + + 2011-12-06T22:36:07Z + + + November 2011 in books + http://www.cantrell.org.uk/david/journal/id/2011-nov-in-books + + 2011-12-02T18:39:16Z + + + October 2011 in books + http://www.cantrell.org.uk/david/journal/id/2011-oct-in-books + + 2011-10-30T15:32:43Z + + + Rugby World Cup roundup + http://www.cantrell.org.uk/david/journal/id/rugby-world-cup-roundup-2011 + + 2011-10-23T13:14:23Z + + + September 2011 in books + http://www.cantrell.org.uk/david/journal/id/2011-sep-in-books + + 2011-10-02T11:30:30Z + + + Amazon Kindle wireless bug - and a bugfix + http://www.cantrell.org.uk/david/journal/id/amazon-kindle-wireless + + 2011-09-29T19:21:32Z + + + Olympic security costs - again + http://www.cantrell.org.uk/david/journal/id/olympic-security-costs-2 + + 2011-09-09T21:53:28Z + + + The Tudors + http://www.cantrell.org.uk/david/journal/id/the-tudors + + 2011-09-08T21:15:48Z + + + August 2011 in books + http://www.cantrell.org.uk/david/journal/id/2011-aug-in-books + + 2011-09-03T10:52:56Z + + + Rum tasting notes + http://www.cantrell.org.uk/david/journal/id/rum-tasting + + 2011-08-03T22:06:40Z + +