From f246934917bcd9688b58dea14b24eaf44aebce0a Mon Sep 17 00:00:00 2001 From: Dan MacTough Date: Sun, 10 Dec 2017 10:01:31 -0500 Subject: [PATCH] Fix html stripping to get entire html-ish substring --- lib/utils.js | 2 +- test/feeds/title-with-angle-brackets.xml | 11 +++++++++++ test/strip-html.js | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/feeds/title-with-angle-brackets.xml create mode 100644 test/strip-html.js diff --git a/lib/utils.js b/lib/utils.js index a396ea8..a97cd09 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -169,7 +169,7 @@ exports.reresolve = reresolve; * @private */ function stripHtml (str) { - return str.replace(/<.*?>/g, ''); + return str.replace(/<+[^>]+?>+/g, ''); } exports.stripHtml = stripHtml; diff --git a/test/feeds/title-with-angle-brackets.xml b/test/feeds/title-with-angle-brackets.xml new file mode 100644 index 0000000..a6ccd67 --- /dev/null +++ b/test/feeds/title-with-angle-brackets.xml @@ -0,0 +1,11 @@ + + + + Channel title + http://example.com/ + Channel + + RSS <<< Title >>> + + + diff --git a/test/strip-html.js b/test/strip-html.js new file mode 100644 index 0000000..bf46254 --- /dev/null +++ b/test/strip-html.js @@ -0,0 +1,18 @@ +describe('strip html', function () { + + var feed = __dirname + '/feeds/title-with-angle-brackets.xml'; + + it('should aggressively strip html', function (done) { + fs.createReadStream(feed).pipe(new FeedParser()) + .once('readable', function () { + var stream = this; + assert.equal(stream.read().title, 'RSS '); + done(); + }) + .on('error', function (err) { + assert.ifError(err); + done(err); + }); + }); + +});