Skip to content

Commit

Permalink
Fix: stripTags strips things that aren't tags
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfalgout committed Jan 13, 2016
1 parent c1f7b1f commit f620c5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stripTags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var makeString = require('./helper/makeString');
var tagsAndComments = /<\/?([a-z][a-z0-9]*)\b[^>]*>|<!--[\s\S]*?-->/gi;

module.exports = function stripTags(str) {
return makeString(str).replace(/<\/?[^>]+>/g, '');
return makeString(str).replace(tagsAndComments, '');
};
1 change: 1 addition & 0 deletions tests/stripTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test('#stripTags', function() {
equal(stripTags('a <a href="#">link</a>'), 'a link');
equal(stripTags('a <a href="#">link</a><script>alert("hello world!")</scr'+'ipt>'), 'a linkalert("hello world!")');
equal(stripTags('<html><body>hello world</body></html>'), 'hello world');
equal(stripTags('I have < I want, but that is > nothing'), 'I have < I want, but that is > nothing');
equal(stripTags(123), '123');
equal(stripTags(''), '');
equal(stripTags(null), '');
Expand Down

0 comments on commit f620c5c

Please sign in to comment.