diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
index 493c0dbfb..cbaec9275 100644
--- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
+++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
@@ -163,16 +163,18 @@ sub generateFeed {
}
my $cache = WebGUI::Cache->new($self->session, $url, "RSS");
my $value = $cache->get;
+ #warn "got this: $value\n";
unless ($value) {
$value = $cache->setByHTTP($url, $self->get("cacheTimeout"));
$newlyCached = 1;
}
+ #warn "got this: $value\n";
# if the content can be downgraded, it is either valid latin1 or didn't have
# an HTTP Content-Encoding header. In the second case, XML::FeedPP will take
# care of any encoding specified in the XML prolog
- utf8::downgrade($value, 1);
+ utf8::downgrade($value, 1) ? 1 : 0;
eval {
- my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string', @opt);
+ my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string', xml_deref => 1, @opt);
$feed->merge_channel($singleFeed);
$feed->merge_item($singleFeed);
};
@@ -181,7 +183,6 @@ sub generateFeed {
}
}
-
# build a new feed that matches the term the user is interested in
if ($self->get('hasTerms') ne '') {
my @terms = split /,\s*/, $self->get('hasTerms'); # get the list of terms
diff --git a/t/Asset/Wobject/SyndicatedContent.t b/t/Asset/Wobject/SyndicatedContent.t
index 397d3f13f..4a3857af1 100644
--- a/t/Asset/Wobject/SyndicatedContent.t
+++ b/t/Asset/Wobject/SyndicatedContent.t
@@ -191,21 +191,6 @@ Rich Text editor in the first sentence of the description.",
#
####################################################################
-sub withCachedFeed {
- my ($url, $path, $block) = @_;
- $syndicated_content->update({ rssUrl => $url });
-
- open my $file, '<', WebGUI::Test->getTestCollateralPath($path)
- or die "Unable to get RSS file: $path";
- my $content = do { local $/; <$file> };
- close $file;
-
- my $cache = WebGUI::Cache->new($session, $url, 'RSS');
- $cache->set($content, 60);
- $block->();
- $cache->delete;
-}
-
sub titles_are {
my ($expected, $message) = @_;
my $feed = $syndicated_content->generateFeed;
@@ -213,18 +198,23 @@ sub titles_are {
cmp_deeply \@got, $expected, $message;
}
-$syndicated_content->update({ hasTerms => 'WebGUI' });
+$syndicated_content->update({ hasTerms => 'WebGUI', });
+my $testFeedUrl = 'http://www.example.com/feed.rss';
+$syndicated_content->update({ rssUrl => $testFeedUrl, });
+my $cache = WebGUI::Cache->new($session, $testFeedUrl, 'RSS');
+$cache->set(slurp_rss('tbb.rss'), 60);
+
+my $feed = $syndicated_content->generateFeed;
+
+titles_are(
+ [
+ 'Google Picasa Plugin for WebGUI Gallery',
+ 'WebGUI Roadmap',
+ 'WebGUI 8 Performance',
+ ],
+ 'generateFeed: filters items based on the terms being in title, or description'
+);
-withCachedFeed 'http://www.plainblack.com/tbb.rss', 'tbb.rss', sub {
- titles_are(
- [
- 'Google Picasa Plugin for WebGUI Gallery',
- 'WebGUI Roadmap',
- 'WebGUI 8 Performance',
- ],
- 'generateFeed: filters items based on the terms being in title, or description'
- );
-};
####################################################################
#
@@ -237,13 +227,11 @@ $syndicated_content->update({
hasTerms => '',
maxHeadlines => 50,
});
+$cache->set(slurp_rss('duplicate-link.rss'), 60);
-withCachedFeed 'http://www.oncp.gob.ve/oncp.xml', 'oncp.xml', sub {
- my $oddFeed1 = $syndicated_content->generateFeed();
-
- my @oddItems = $oddFeed1->get_item();
- is (@oddItems, 13, 'feed has items even without pubDates or links');
-};
+my $oddFeed1 = $syndicated_content->generateFeed();
+my @oddItems = $oddFeed1->get_item();
+is (@oddItems, 2, 'feed has items even without pubDates or links');
####################################################################
#
@@ -251,28 +239,36 @@ withCachedFeed 'http://www.oncp.gob.ve/oncp.xml', 'oncp.xml', sub {
#
####################################################################
+$cache->set(slurp_rss('tbb_odd.rss'), 60);
+my @ascending = (
+ 'I have arrived in Lisboa!',
+ 'WebGUI 8 Performance',
+ 'WebGUI Roadmap',
+ 'Google Picasa Plugin for WebGUI Gallery',
+);
+my @descending = reverse @ascending;
+my @feed = (
+ 'WebGUI Roadmap',
+ 'Google Picasa Plugin for WebGUI Gallery',
+ 'I have arrived in Lisboa!',
+ 'WebGUI 8 Performance',
+);
-withCachedFeed 'http://www.plainblack.com/tbb.rss', 'tbb_odd.rss', sub {
- my @ascending = (
- 'I have arrived in Lisboa!',
- 'WebGUI 8 Performance',
- 'WebGUI Roadmap',
- 'Google Picasa Plugin for WebGUI Gallery',
- );
- my @descending = reverse @ascending;
- my @feed = (
- 'WebGUI Roadmap',
- 'Google Picasa Plugin for WebGUI Gallery',
- 'I have arrived in Lisboa!',
- 'WebGUI 8 Performance',
- );
+$syndicated_content->update({ sortItems => 'pubDate_asc' });
+titles_are \@ascending, 'ascending sort';
- $syndicated_content->update({ sortItems => 'pubDate_asc' });
- titles_are \@ascending, 'ascending sort';
+$syndicated_content->update({ sortItems => 'pubDate_des' });
+titles_are \@descending, 'descending sort';
- $syndicated_content->update({ sortItems => 'pubDate_des' });
- titles_are \@descending, 'descending sort';
+$syndicated_content->update({ sortItems => 'feed' });
+titles_are \@feed, 'feed order';
- $syndicated_content->update({ sortItems => 'feed' });
- titles_are \@feed, 'feed order';
-};
+sub slurp_rss {
+ my $file = shift;
+ my $filepath = WebGUI::Test->getTestCollateralPath('rss/' . $file);
+ open my $fh, '<', $filepath
+ or die "Unable to get RSS file $file: $!";
+ my $content = do { local $/; <$fh> };
+ close $fh;
+ return $content;
+}
diff --git a/t/Asset/Wobject/SyndicatedContent/encodings.t b/t/Asset/Wobject/SyndicatedContent/encodings.t
new file mode 100644
index 000000000..b84eca499
--- /dev/null
+++ b/t/Asset/Wobject/SyndicatedContent/encodings.t
@@ -0,0 +1,119 @@
+#-------------------------------------------------------------------
+# WebGUI is Copyright 2001-2009 Plain Black Corporation.
+#-------------------------------------------------------------------
+# Please read the legal notices (docs/legal.txt) and the license
+# (docs/license.txt) that came with this distribution before using
+# this software.
+#-------------------------------------------------------------------
+# http://www.plainblack.com info@plainblack.com
+#-------------------------------------------------------------------
+
+use FindBin;
+use strict;
+use File::Spec;
+use lib "$FindBin::Bin/../../../lib";
+
+# The goal of this test is to test the creation of
+# and expose any bugs of SyndicatedContent Wobjects.
+
+use WebGUI::Test;
+use Test::More; # increment this value for each test you create
+use WebGUI::Session;
+plan skip_all => 'set TEST_ENCODINGS to enable this test' unless $ENV{TEST_ENCODINGS};
+plan tests => 13; # increment this value for each test you create
+use Test::Deep;
+use WebGUI::Asset::Wobject::SyndicatedContent;
+use XML::FeedPP;
+use WebGUI::Cache;
+
+my $session = WebGUI::Test->session;
+my %var;
+
+##############################
+## SETUP ##
+##############################
+
+# Do our work in the import node
+my $node = WebGUI::Asset->getImportNode($session);
+
+# Create a version tag to work in
+my $versionTag = WebGUI::VersionTag->getWorking($session);
+$versionTag->set({name=>"SyndicatedContent Test"});
+addToCleanup($versionTag);
+my $syndicated_content = $node->addChild({className=>'WebGUI::Asset::Wobject::SyndicatedContent'});
+
+####################################################################
+#
+# Encoding tests
+#
+####################################################################
+
+my $UTF8_BOM = "\xEF\xBB\xBF";
+
+my $testFeedUrl = 'http://www.example.com/feed.rss';
+$syndicated_content->update({
+ hasTerms => '',
+ rssUrl => $testFeedUrl,
+});
+my $cache = WebGUI::Cache->new($session, $testFeedUrl, 'RSS');
+
+my $utf8_es = slurp_rss('utf8-es.rss');
+my $utf8_ru = slurp_rss('utf8-ru.rss');
+my $entity_es = slurp_rss('entity-es.rss');
+my $entity_ru = slurp_rss('entity-ru.rss');
+my $utf8_no_prolog = Encode::decode_utf8(slurp_rss('utf8-no-prolog-encoding.rss'));
+my $iso_8859_1 = slurp_rss('iso-8859-1.rss');
+my $iso_8859_5 = slurp_rss('iso-8859-5.rss');
+
+my $es_title = "PM captur\x{00F3} a tres delincuentes que robaron agencia bancaria en San Mart\x{00ED}n";
+my $ru_title = "\x{412}\x{438}\x{43a}\x{438}\x{43f}\x{435}\x{434}\x{438}\x{44f} - \x{421}\x{432}\x{435}\x{436}\x{438}\x{435} \x{43f}\x{440}\x{430}\x{432}\x{43a}\x{438} [ru]";
+
+$cache->set($utf8_es, 60);
+is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, UTF-8 encoded';
+
+$cache->set($utf8_ru, 60);
+is $syndicated_content->generateFeed->title, $ru_title, 'Russian, UTF-8 encoded';
+
+$cache->set($entity_es, 60);
+is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, Entity encoded, utf8 flag off';
+
+$cache->set($entity_ru, 60);
+is $syndicated_content->generateFeed->title, $ru_title, 'Russian, Entity encoded, utf8 flag off';
+
+$cache->set($UTF8_BOM . $utf8_es, 60);
+is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, UTF-8 encoded, With BOM';
+
+$cache->set(Encode::decode_utf8($utf8_es), 60);
+is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, Decoded';
+
+$cache->set(Encode::decode_utf8($utf8_ru), 60);
+is $syndicated_content->generateFeed->title, $ru_title, 'Russian, Decoded';
+
+$cache->set(Encode::decode_utf8($entity_es), 60);
+is $syndicated_content->generateFeed->title, $es_title, 'Latin-1, Entity encoded, utf8 flag on';
+
+$cache->set(Encode::decode_utf8($entity_ru), 60);
+is $syndicated_content->generateFeed->title, $ru_title, 'Russian, Entity encoded, utf8 flag on';
+
+$cache->set($UTF8_BOM . Encode::decode_utf8($utf8_es), 60);
+is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, Decoded, With BOM';
+
+$cache->set($utf8_no_prolog, 60);
+is $syndicated_content->generateFeed->title, $es_title, 'No encoding in prolog, Decoded';
+
+$cache->set($iso_8859_1, 60);
+is $syndicated_content->generateFeed->title, $es_title, 'ISO-8859-1 encoded';
+$cache->set($iso_8859_5, 60);
+is $syndicated_content->generateFeed->title, $ru_title, 'ISO-8859-5 encoded';
+
+$cache->delete;
+
+sub slurp_rss {
+ my $file = shift;
+ my $filepath = WebGUI::Test->getTestCollateralPath('rss/' . $file);
+ open my $fh, '<', $filepath
+ or die "Unable to get RSS file $file: $!";
+ my $content = do { local $/; <$fh> };
+ close $fh;
+ return $content;
+}
diff --git a/t/supporting_collateral/oncp.xml b/t/supporting_collateral/oncp.xml
deleted file mode 100644
index 7e5abe22a..000000000
--- a/t/supporting_collateral/oncp.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
- http://www.oncp.gob.ve
- Informacin Financiera
- es-ve
- Oficina Nacional de Crdito Pblico - 2009
-
- Oficina Nacional de Crdito Pblico
- http://www.oncp.gob.ve/data/themes/digital//banner/oncp.png
- http://www.oncp.gob.ve
-
-
-
-
- http://www.oncp.gob.ve
-
- http://www.oncp.gob.ve
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
- http://www.oncp.gob.ve
-
-
-
-
-
-
diff --git a/t/supporting_collateral/rss/duplicate-link.rss b/t/supporting_collateral/rss/duplicate-link.rss
new file mode 100644
index 000000000..ea464da8e
--- /dev/null
+++ b/t/supporting_collateral/rss/duplicate-link.rss
@@ -0,0 +1,19 @@
+
+
+ Duplicate Link Feed Title
+ http://www.example.com/
+ Duplicate Link Feed Description
+
+ Duplicate Link Feed Item 1
+ http://www.example.com/
+ Duplicate Link Feed Item 1
+ http://www.example.com/
+
+
+ Duplicate Link Feed Item 2
+ http://www.example.com/
+ Duplicate Link Feed Item 2
+ http://www.example.com/
+
+
+
diff --git a/t/supporting_collateral/rss/entity-es.rss b/t/supporting_collateral/rss/entity-es.rss
new file mode 100644
index 000000000..8c9f29136
--- /dev/null
+++ b/t/supporting_collateral/rss/entity-es.rss
@@ -0,0 +1,15 @@
+
+
+
+ PM capturó a tres delincuentes que robaron agencia bancaria en San Martín
+ http://www.vtv.gob.ve/rss-noticias-nacionales
+ RSS Noticias Nacionales
+ es
+
+ PM capturó a tres delincuentes que robaron agencia bancaria en San Martín
+ http://www.vtv.gob.ve/noticias-nacionales/25087
+ <p>Efectivos de la Policía Metropolitana (PM) de Caracas capturaron, este lunes en horas de la mañana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegráfico de Venezuela, Ipostel, en la avenida José Ángel Lamas, San Martín.</p>
+ Mon, 19 Oct 2009 15:42:17 -0400
+
+
+
diff --git a/t/supporting_collateral/rss/entity-ru.rss b/t/supporting_collateral/rss/entity-ru.rss
new file mode 100644
index 000000000..047e5ce1e
--- /dev/null
+++ b/t/supporting_collateral/rss/entity-ru.rss
@@ -0,0 +1,14 @@
+
+
+
+ Википедия - Свежие правки [ru]
+ http://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:RecentChanges
+ Отслеживать последние изменения в вики в этом потоке.
+ ru
+
+ Йиржи из Подебрад
+ http://ru.wikipedia.org/w/index.php?title=%D0%99%D0%B8%D1%80%D0%B6%D0%B8_%D0%B8%D0%B7_%D0%9F%D0%BE%D0%B4%D0%B5%D0%B1%D1%80%D0%B0%D0%B4&diff=19271780&oldid=prev
+ <div>Происходил из знатной и влиятельной чешской семьи, примкнувшей к гуситскому лагерю. Отец Йиржи, Виктор из [[Подебрады|Подебрад]], был одним из руководителей [[табориты|таборитов]];— радикального крыла гуситов, однако через некоторое время присоединился к умеренным утраквистам. Сам Йиржи из Подебрад, будучи четырнадцатилетним мальчиком, участвовал в [[битва под Липанами|битве под Липанами]] в [[1434]], в которой умеренные гуситы, объединившиеся с австрийцами, нанесли поражение радикальным. В общем, при [[Сигизмунд (император )|Сигизмунде Люксембургском]] семья Йиржи из Подебрад принадлежала к умеренной партии, но после избрания королем Чехии с подачи католической партии Альбрехта V Австрийского (немецкого императора [[Альбрехт II (император)|Альбрехта II]]), отец и сын примкнули к оппозиции, желавшей избрания [[Казимир III|Казимира Польского]].</div>
+ Tue, 20 Oct 2009 00:00:44 GMT
+
+
diff --git a/t/supporting_collateral/rss/iso-8859-1.rss b/t/supporting_collateral/rss/iso-8859-1.rss
new file mode 100644
index 000000000..7233ac7d4
--- /dev/null
+++ b/t/supporting_collateral/rss/iso-8859-1.rss
@@ -0,0 +1,15 @@
+
+
+
+ PM captur a tres delincuentes que robaron agencia bancaria en San Martn
+ http://www.vtv.gob.ve/rss-noticias-nacionales
+ RSS Noticias Nacionales
+ es
+
+ PM captur a tres delincuentes que robaron agencia bancaria en San Martn
+ http://www.vtv.gob.ve/noticias-nacionales/25087
+ <p>Efectivos de la Polica Metropolitana (PM) de Caracas capturaron, este lunes en horas de la maana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegrfico de Venezuela, Ipostel, en la avenida Jos ngel Lamas, San Martn.</p>
+ Mon, 19 Oct 2009 15:42:17 -0400
+
+
+
diff --git a/t/supporting_collateral/rss/iso-8859-5.rss b/t/supporting_collateral/rss/iso-8859-5.rss
new file mode 100644
index 000000000..f0a37d88b
--- /dev/null
+++ b/t/supporting_collateral/rss/iso-8859-5.rss
@@ -0,0 +1,14 @@
+
+
+
+ - [ru]
+ http://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:RecentChanges
+ .
+ ru
+
+
+ http://ru.wikipedia.org/w/index.php?title=%D0%99%D0%B8%D1%80%D0%B6%D0%B8_%D0%B8%D0%B7_%D0%9F%D0%BE%D0%B4%D0%B5%D0%B1%D1%80%D0%B0%D0%B4&diff=19271780&oldid=prev
+ <div> , . , [[|]], [[|]];? , . , , [[ | ]] [[1434]], , , . , [[ ( )| ]] , V ( [[ II ()| II]]), , [[ III| ]].</div>
+ Tue, 20 Oct 2009 00:00:44 GMT
+
+
diff --git a/t/supporting_collateral/tbb.rss b/t/supporting_collateral/rss/tbb.rss
similarity index 100%
rename from t/supporting_collateral/tbb.rss
rename to t/supporting_collateral/rss/tbb.rss
diff --git a/t/supporting_collateral/tbb_odd.rss b/t/supporting_collateral/rss/tbb_odd.rss
similarity index 100%
rename from t/supporting_collateral/tbb_odd.rss
rename to t/supporting_collateral/rss/tbb_odd.rss
diff --git a/t/supporting_collateral/rss/utf8-es.rss b/t/supporting_collateral/rss/utf8-es.rss
new file mode 100644
index 000000000..dafc44806
--- /dev/null
+++ b/t/supporting_collateral/rss/utf8-es.rss
@@ -0,0 +1,15 @@
+
+
+
+ PM capturó a tres delincuentes que robaron agencia bancaria en San Martín
+ http://www.vtv.gob.ve/rss-noticias-nacionales
+ RSS Noticias Nacionales
+ es
+
+ PM capturó a tres delincuentes que robaron agencia bancaria en San Martín
+ http://www.vtv.gob.ve/noticias-nacionales/25087
+ <p>Efectivos de la Policía Metropolitana (PM) de Caracas capturaron, este lunes en horas de la mañana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegráfico de Venezuela, Ipostel, en la avenida José Ángel Lamas, San Martín.</p>
+ Mon, 19 Oct 2009 15:42:17 -0400
+
+
+
diff --git a/t/supporting_collateral/rss/utf8-no-prolog-encoding.rss b/t/supporting_collateral/rss/utf8-no-prolog-encoding.rss
new file mode 100644
index 000000000..3027241a2
--- /dev/null
+++ b/t/supporting_collateral/rss/utf8-no-prolog-encoding.rss
@@ -0,0 +1,15 @@
+
+
+
+ PM capturó a tres delincuentes que robaron agencia bancaria en San Martín
+ http://www.vtv.gob.ve/rss-noticias-nacionales
+ RSS Noticias Nacionales
+ es
+
+ PM capturó a tres delincuentes que robaron agencia bancaria en San Martín
+ http://www.vtv.gob.ve/noticias-nacionales/25087
+ <p>Efectivos de la Policía Metropolitana (PM) de Caracas capturaron, este lunes en horas de la mañana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegráfico de Venezuela, Ipostel, en la avenida José Ángel Lamas, San Martín.</p>
+ Mon, 19 Oct 2009 15:42:17 -0400
+
+
+
diff --git a/t/supporting_collateral/rss/utf8-ru.rss b/t/supporting_collateral/rss/utf8-ru.rss
new file mode 100644
index 000000000..6b65d99b7
--- /dev/null
+++ b/t/supporting_collateral/rss/utf8-ru.rss
@@ -0,0 +1,14 @@
+
+
+
+ Википедия - Свежие правки [ru]
+ http://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:RecentChanges
+ Отслеживать последние изменения в вики в этом потоке.
+ ru
+
+ Йиржи из Подебрад
+ http://ru.wikipedia.org/w/index.php?title=%D0%99%D0%B8%D1%80%D0%B6%D0%B8_%D0%B8%D0%B7_%D0%9F%D0%BE%D0%B4%D0%B5%D0%B1%D1%80%D0%B0%D0%B4&diff=19271780&oldid=prev
+ <div>Происходил из знатной и влиятельной чешской семьи, примкнувшей к гуситскому лагерю. Отец Йиржи, Виктор из [[Подебрады|Подебрад]], был одним из руководителей [[табориты|таборитов]];— радикального крыла гуситов, однако через некоторое время присоединился к умеренным утраквистам. Сам Йиржи из Подебрад, будучи четырнадцатилетним мальчиком, участвовал в [[битва под Липанами|битве под Липанами]] в [[1434]], в которой умеренные гуситы, объединившиеся с австрийцами, нанесли поражение радикальным. В общем, при [[Сигизмунд (император )|Сигизмунде Люксембургском]] семья Йиржи из Подебрад принадлежала к умеренной партии, но после избрания королем Чехии с подачи католической партии Альбрехта V Австрийского (немецкого императора [[Альбрехт II (император)|Альбрехта II]]), отец и сын примкнули к оппозиции, желавшей избрания [[Казимир III|Казимира Польского]].</div>
+ Tue, 20 Oct 2009 00:00:44 GMT
+
+