Make regex used in `stripTags` stricter. (igor, kangax) [#674 state:resolved]
This commit is contained in:
parent
cb729625ae
commit
cc0a75fe19
|
@ -122,9 +122,11 @@ Object.extend(String.prototype, (function() {
|
|||
* String#stripTags() -> String
|
||||
*
|
||||
* Strips a string of any HTML tag.
|
||||
* Note that `stripTags` will only strip HTML4.01 tags (such as - div, span and abbr)
|
||||
* It will not strip namespace-prefixed tags such as "h:table" or "xsl:template"
|
||||
**/
|
||||
function stripTags() {
|
||||
return this.replace(/<\/?[^>]+>/gi, '');
|
||||
return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -208,6 +208,7 @@ new Test.Unit.Runner({
|
|||
this.assertEqual('hello world', '<a href="#" onclick="moo!">hello</a> world'.stripTags());
|
||||
this.assertEqual('hello world', 'h<b><em>e</em></b>l<i>l</i>o w<span class="moo" id="x"><b>o</b></span>rld'.stripTags());
|
||||
this.assertEqual('1\n2', '1\n2'.stripTags());
|
||||
this.assertEqual('one < two blah baz', 'one < two <a href="#" title="foo > bar">blah</a> <input disabled>baz'.stripTags());
|
||||
},
|
||||
|
||||
testStripScripts: function() {
|
||||
|
|
Loading…
Reference in New Issue