diff --git a/src/lang/string.js b/src/lang/string.js index 2798bcc..b9c5f50 100644 --- a/src/lang/string.js +++ b/src/lang/string.js @@ -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, ''); } /** diff --git a/test/unit/string_test.js b/test/unit/string_test.js index 5d7ce33..93308a4 100644 --- a/test/unit/string_test.js +++ b/test/unit/string_test.js @@ -208,6 +208,7 @@ new Test.Unit.Runner({ this.assertEqual('hello world', 'hello world'.stripTags()); this.assertEqual('hello world', 'hello world'.stripTags()); this.assertEqual('1\n2', '1\n2'.stripTags()); + this.assertEqual('one < two blah baz', 'one < two blah baz'.stripTags()); }, testStripScripts: function() {