Skip to content

Commit

Permalink
fix for string.stripTags()
Browse files Browse the repository at this point in the history
  • Loading branch information
der-On committed Feb 13, 2014
1 parent bed76b7 commit e3cfec7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/string.js
Expand Up @@ -791,15 +791,15 @@ string = new (function () {
@function
@return {String} A String with HTML tags removed.
@description Strips HTML tags from a string.
@param {String} string The string to strip HTML tags from
@param {String} The string to strip HTML tags from
@param {String|Array} A String or Array containing allowed tags. e.g. "<br><p>"
*/
this.stripTags = function(string, allowed) {
// taken from http://phpjs.org/functions/strip_tags/
var allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
comments = /<!--[\s\S]*?-->/gi;
return input.replace(comments, '').replace(tags, function ($0, $1) {
return string.replace(comments, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});
}
Expand Down

0 comments on commit e3cfec7

Please sign in to comment.