Subject: | permaLink fixes No. 2 |
This patch fixes the permaLink/guid problem that was present in the
code since some previous patching, as illustrated by the documentation
of XML::RSS.
With this patch:
1. If the isPermaLink attribute in the guid element is not set to
false or missing then permaLink contains the value of the guid tag.
2. If the isPermaLink attribute is set to false then guid contains it.
This patch fixes this problem.
I don't recall which issue it referred to originally, and I don't have
it in my records.
Regards,
Shlomi Fish
Subject: | XML-RSS-permaLink-2.diff |
=== t/2.0-permalink.t
==================================================================
--- t/2.0-permalink.t (/mirror/XML-RSS/trunk) (revision 494)
+++ t/2.0-permalink.t (/local/XML-RSS/local-trunk) (revision 494)
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 4;
use File::Spec;
use XML::RSS;
@@ -15,16 +15,25 @@
my $item_with_guid_false = $rss->{'items'}->[2];
# TEST
-ok ($item_with_guid_true->{"permaLink"},
- "guid is set to true, so the permalink should be true"
+is ($item_with_guid_true->{"permaLink"},
+ "http://community.livejournal.com/lj_dev/714037.html",
+ "guid's isPermaLink is set to true, so the item permalink property should be set to the value of the guid tag"
);
# TEST
-ok ($item_with_guid_missing->{"permaLink"},
- "guid is missing, so the permalink should be true"
+is ($item_with_guid_missing->{"permaLink"},
+ "http://community.livejournal.com/lj_dev/713810.html",
+ "guid's isPermaLink is missing, so the item permalink property should be set to the value of the guid tag"
);
# TEST
ok ((!$item_with_guid_false->{"permaLink"}),
- "guid is false, so the permalink should be false"
+ "guid's isPermaLink is false, so the permalink should be false"
);
+
+# TEST
+is ($item_with_guid_false->{"guid"},
+ "http://community.livejournal.com/lj_dev/713549.html",
+ "guid's isPermaLink is false so item->{guid} should be equal to" .
+ " the contents of the guid element"
+);
=== t/test_manifest
==================================================================
--- t/test_manifest (/mirror/XML-RSS/trunk) (revision 494)
+++ t/test_manifest (/local/XML-RSS/local-trunk) (revision 494)
@@ -24,4 +24,4 @@
pod-coverage.t
rss2-gt-encoding.t
charset1.t
-xml-header.t
\ No newline at end of file
+xml-header.t
Property changes on: t
___________________________________________________________________
Name: svn:ignore
+1.0-generated.xml
+2.0-generated.xml
+charset1-generated.xml
+
=== MANIFEST
==================================================================
--- MANIFEST (/mirror/XML-RSS/trunk) (revision 494)
+++ MANIFEST (/local/XML-RSS/local-trunk) (revision 494)
@@ -60,4 +60,3 @@
t/version.t
t/xml-header.t
TODO
-
=== lib/XML/RSS.pm
==================================================================
--- lib/XML/RSS.pm (/mirror/XML-RSS/trunk) (revision 494)
+++ lib/XML/RSS.pm (/local/XML-RSS/local-trunk) (revision 494)
@@ -1689,7 +1689,20 @@
(!$ns && !$self->{rss_namespace}) ||
($ns eq $self->{rss_namespace})
) {
- $self->{'items'}->[$self->{num_items}-1]->{$self->current_element} .= $cdata;
+ my $elem = $self->current_element;
+ if (@{$self->{'items'}} < $self->{num_items})
+ {
+ push @{$self->{items}}, {};
+ }
+ my $item = $self->{'items'}->[$self->{num_items}-1];
+ if ($elem eq "guid")
+ {
+ $item->{$item->{isPermaLink} ? "permaLink" : "guid"} .= $cdata;
+ }
+ else
+ {
+ $item->{$elem} .= $cdata;
+ }
} else {
# If it's in another namespace
$self->{'items'}->[$self->{num_items}-1]->{$ns}->{$self->current_element} .= $cdata;
@@ -1833,7 +1846,7 @@
}
# guid element is a permanent link unless isPermaLink attribute is set to false
} elsif ( $el eq 'guid' ) {
- $self->{'items'}->[$self->{num_items} - 1]->{'permaLink'} =
+ $self->{'items'}->[$self->{num_items} - 1]->{'isPermaLink'} =
!(exists($attribs{'isPermaLink'}) &&
($attribs{'isPermaLink'} eq 'false')
);