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 Feb 24, 2016
1 parent c1f7b1f commit f033d27
Show file tree
Hide file tree
Showing 2 changed files with 7 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, '');
};
5 changes: 5 additions & 0 deletions tests/stripTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ 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('<h1 id="foo" data-foo="bar">hello world</body></h1>'), 'hello world');
equal(stripTags('<web-component>hello world</web-component>'), 'hello world');
equal(stripTags('<ReactComponent.Title>hello world</ReactComponent.Title>'), 'hello world');
equal(stripTags('I have < I want, but that is > nothing'), 'I have < I want, but that is > nothing');
equal(stripTags('<!-- a html comment --->hello world<!-- a html comment --->'), 'hello world');
equal(stripTags(123), '123');
equal(stripTags(''), '');
equal(stripTags(null), '');
Expand Down

0 comments on commit f033d27

Please sign in to comment.