summaryrefslogtreecommitdiffstats
path: root/mailnews/extensions/newsblog/content/feed-parser.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-11 01:04:46 -0500
committerMatt A. Tobin <email@mattatobin.com>2019-11-11 01:04:46 -0500
commit0707a51eaddec22ab760e27050e2fcefab2cdae5 (patch)
tree03577a3ee56df77cff3e8dee281b196bde8dc95b /mailnews/extensions/newsblog/content/feed-parser.js
parent0903ef35611c8d2a966f057d2e74437a73de71df (diff)
downloadUXP-0707a51eaddec22ab760e27050e2fcefab2cdae5.tar
UXP-0707a51eaddec22ab760e27050e2fcefab2cdae5.tar.gz
UXP-0707a51eaddec22ab760e27050e2fcefab2cdae5.tar.lz
UXP-0707a51eaddec22ab760e27050e2fcefab2cdae5.tar.xz
UXP-0707a51eaddec22ab760e27050e2fcefab2cdae5.zip
Bug 1423487 - Support multiple authors in RSS feeds.
Tag #1273
Diffstat (limited to 'mailnews/extensions/newsblog/content/feed-parser.js')
-rw-r--r--mailnews/extensions/newsblog/content/feed-parser.js84
1 files changed, 65 insertions, 19 deletions
diff --git a/mailnews/extensions/newsblog/content/feed-parser.js b/mailnews/extensions/newsblog/content/feed-parser.js
index 660333422..03fc72b22 100644
--- a/mailnews/extensions/newsblog/content/feed-parser.js
+++ b/mailnews/extensions/newsblog/content/feed-parser.js
@@ -222,9 +222,10 @@ FeedParser.prototype =
tags = this.childrenByTagNameNS(itemNode, nsURI, "author");
if (!tags)
tags = this.childrenByTagNameNS(itemNode, FeedUtils.DC_NS, "creator");
- item.author = this.getNodeValue(tags ? tags[0] : null) ||
- aFeed.title ||
- item.author;
+ let author = this.getNodeValue(tags ? tags[0] : null) ||
+ aFeed.title;
+ author = this.cleanAuthorName(author);
+ item.author = author ? ["<" + author + ">"] : item.author;
tags = this.childrenByTagNameNS(itemNode, nsURI, "pubDate");
if (!tags || !this.getNodeValue(tags[0]))
@@ -386,10 +387,12 @@ FeedParser.prototype =
item.id = item.url;
item.url = this.validLink(item.url);
- item.author = this.getRDFTargetValue(ds, itemResource, FeedUtils.DC_CREATOR) ||
- this.getRDFTargetValue(ds, channel, FeedUtils.DC_CREATOR) ||
- aFeed.title ||
- item.author;
+ let author = this.getRDFTargetValue(ds, itemResource, FeedUtils.DC_CREATOR) ||
+ this.getRDFTargetValue(ds, channel, FeedUtils.DC_CREATOR) ||
+ aFeed.title;
+ author = this.cleanAuthorName(author);
+ item.author = author ? ["<" + author + ">"] : item.author;
+
item.date = this.getRDFTargetValue(ds, itemResource, FeedUtils.DC_DATE) ||
item.date;
item.content = this.getRDFTargetValueFormatted(ds, itemResource,
@@ -608,7 +611,7 @@ FeedParser.prototype =
continue;
}
- // XXX Support multiple authors.
+ // Support multiple authors.
tags = this.childrenByTagNameNS(itemNode, FeedUtils.ATOM_IETF_NS, "source");
let source = tags ? tags[0] : null;
@@ -618,22 +621,42 @@ FeedParser.prototype =
if (!tags)
tags = this.childrenByTagNameNS(channel, FeedUtils.ATOM_IETF_NS, "author");
- let authorEl = tags ? tags[0] : null;
-
- let author = "";
- if (authorEl)
- {
- tags = this.childrenByTagNameNS(authorEl, FeedUtils.ATOM_IETF_NS, "name");
+ let authorTags = tags || [];
+ let authors = [];
+ for (let authorTag of authorTags) {
+ let author = "";
+ tags = this.childrenByTagNameNS(authorTag, FeedUtils.ATOM_IETF_NS, "name");
let name = this.getNodeValue(tags ? tags[0] : null);
- tags = this.childrenByTagNameNS(authorEl, FeedUtils.ATOM_IETF_NS, "email");
+ tags = this.childrenByTagNameNS(authorTag, FeedUtils.ATOM_IETF_NS, "email");
let email = this.getNodeValue(tags ? tags[0] : null);
- if (name)
- author = name + (email ? " <" + email + ">" : "");
- else if (email)
+ if (name) {
+ name = this.cleanAuthorName(name);
+ if (email) {
+ if (!email.match(/^<.*>$/)) {
+ email = " <" + email + ">";
+ }
+ author = name + email;
+ } else {
+ author = "<" + name + ">";
+ }
+ } else if (email) {
author = email;
+ }
+ if (author) {
+ authors.push(author);
+ }
}
- item.author = author || item.author || aFeed.title;
+ if (authors.length == 0) {
+ tags = this.childrenByTagNameNS(channel, FeedUtils.DC_NS, "publisher");
+ let author = this.getNodeValue(tags ? tags[0] : null) ||
+ aFeed.title;
+ author = this.cleanAuthorName(author);
+ item.author = author ? ["<" + author + ">"] : item.author;
+ } else {
+ item.author = authors;
+ }
+ FeedUtils.log.trace("FeedParser.parseAsAtomIETF: author(s) - " + item.author);
tags = this.childrenByTagNameNS(itemNode, FeedUtils.ATOM_IETF_NS, "updated");
if (!tags || !this.getNodeValue(tags[0]))
@@ -801,6 +824,29 @@ FeedParser.prototype =
return content ? content : null;
},
+ /**
+ * Return a cleaned up author name value.
+ *
+ * @param {String} authorString - A string.
+ * @returns {String} - A clean string value.
+ */
+ cleanAuthorName(authorString) {
+ if (!authorString) {
+ return "";
+ }
+ FeedUtils.log.trace("FeedParser.cleanAuthor: author1 - " + authorString);
+ let author = authorString.replace(/[\n\r\t]+/g, " ")
+ .replace(/"/g, '\\"')
+ .trim();
+ // If the name contains special chars, quote it.
+ if (author.match(/[<>@,"]/)) {
+ author = '"' + author + '"';
+ }
+ FeedUtils.log.trace("FeedParser.cleanAuthor: author2 - " + author);
+
+ return author;
+ },
+
getRDFTargetValue: function(ds, source, property)
{
let nodeValue = this.getRDFTargetValueRaw(ds, source, property);