Skip to content

Commit

Permalink
Fix html stripping to get entire html-ish substring
Browse files Browse the repository at this point in the history
  • Loading branch information
danmactough committed Jul 15, 2018
1 parent c5b4c77 commit f246934
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ exports.reresolve = reresolve;
* @private
*/
function stripHtml (str) {
return str.replace(/<.*?>/g, '');
return str.replace(/<+[^>]+?>+/g, '');
}

exports.stripHtml = stripHtml;
11 changes: 11 additions & 0 deletions test/feeds/title-with-angle-brackets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Channel title</title>
<link>http://example.com/</link>
<description>Channel</description>
<item>
<title>RSS &lt;&lt;&lt; Title &gt;&gt;&gt;</title>
</item>
</channel>
</rss>
18 changes: 18 additions & 0 deletions test/strip-html.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

});

0 comments on commit f246934

Please sign in to comment.