From b9b778647720b8a1145cf0a3e06d9e52f415a67d Mon Sep 17 00:00:00 2001 From: ngosang Date: Tue, 4 Aug 2015 01:15:40 +0200 Subject: [PATCH] [RSS] Trim elements text in RSS articles --- src/gui/rss/rssparser.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/rss/rssparser.cpp b/src/gui/rss/rssparser.cpp index 0aaf19582..fe4c5ab5d 100644 --- a/src/gui/rss/rssparser.cpp +++ b/src/gui/rss/rssparser.cpp @@ -254,7 +254,7 @@ void RssParser::parseRssArticle(QXmlStreamReader& xml, const QString& feedUrl) if (xml.isStartElement()) { if (xml.name() == "title") - article["title"] = xml.readElementText(); + article["title"] = xml.readElementText().trimmed(); else if (xml.name() == "enclosure") { if (xml.attributes().value("type") == "application/x-bittorrent") article["torrent_url"] = xml.attributes().value("url").toString(); @@ -267,13 +267,13 @@ void RssParser::parseRssArticle(QXmlStreamReader& xml, const QString& feedUrl) article["news_link"] = link; } else if (xml.name() == "description") - article["description"] = xml.readElementText(); + article["description"] = xml.readElementText().trimmed(); else if (xml.name() == "pubDate") - article["date"] = parseDate(xml.readElementText()); + article["date"] = parseDate(xml.readElementText().trimmed()); else if (xml.name() == "author") - article["author"] = xml.readElementText(); + article["author"] = xml.readElementText().trimmed(); else if (xml.name() == "guid") - article["id"] = xml.readElementText(); + article["id"] = xml.readElementText().trimmed(); } } @@ -343,7 +343,7 @@ void RssParser::parseAtomArticle(QXmlStreamReader& xml, const QString& feedUrl, // Workaround for CDATA (QString cannot parse html escapes on it's own) QTextDocument doc; doc.setHtml(xml.readElementText()); - article["title"] = doc.toPlainText(); + article["title"] = doc.toPlainText().trimmed(); } else if (xml.name() == "link") { QString link = ( xml.attributes().isEmpty() ? @@ -373,13 +373,13 @@ void RssParser::parseAtomArticle(QXmlStreamReader& xml, const QString& feedUrl, // Actually works great for non-broken content too QString feedText = xml.readElementText(QXmlStreamReader::IncludeChildElements); if (!feedText.isEmpty()) - article["description"] = feedText; + article["description"] = feedText.trimmed(); double_content = true; } else if (xml.name() == "updated"){ // ATOM uses standard compliant date, don't do fancy stuff - QDateTime articleDate = QDateTime::fromString(xml.readElementText(), Qt::ISODate); + QDateTime articleDate = QDateTime::fromString(xml.readElementText().trimmed(), Qt::ISODate); article["date"] = ( articleDate.isValid() ? articleDate : QDateTime::currentDateTime() ); @@ -388,12 +388,12 @@ void RssParser::parseAtomArticle(QXmlStreamReader& xml, const QString& feedUrl, xml.readNext(); while(xml.name() != "author") { if(xml.name() == "name") - article["author"] = xml.readElementText(); + article["author"] = xml.readElementText().trimmed(); xml.readNext(); } } else if (xml.name() == "id") - article["id"] = xml.readElementText(); + article["id"] = xml.readElementText().trimmed(); } }