优化性能

This commit is contained in:
Lei Zongmin
2013-05-07 13:46:49 +08:00
parent 92050259d2
commit 4a2428dc1a
2 changed files with 9 additions and 5 deletions

View File

@@ -143,9 +143,10 @@ FilterXSS.prototype.filterAttributes = function (tagName, attrs) {
var me = this;
var whites = this.whiteList[tagName];
var lastPos = 0;
var _attrs = [];
var _attrs = '';
var tmpName = false;
var hasSprit = false;
var addAttr = function (name, value) {
name = name.trim();
if (!hasSprit && name === '/') {
@@ -172,9 +173,10 @@ FilterXSS.prototype.filterAttributes = function (tagName, attrs) {
value = newValue;
}
}
_attrs.push(name + (value ? '="' + value + '"' : ''));
_attrs += name + (value ? '="' + value + '"' : '') + ' ';
}
};
for (var i = 0, len = attrs.length; i < len; i++) {
var c = attrs[i];
if (tmpName === false && c === '=') {
@@ -209,6 +211,7 @@ FilterXSS.prototype.filterAttributes = function (tagName, attrs) {
continue;
}
}
if (lastPos < attrs.length) {
if (tmpName === false) {
addAttr(attrs.slice(lastPos));
@@ -216,8 +219,9 @@ FilterXSS.prototype.filterAttributes = function (tagName, attrs) {
addAttr(tmpName, attrs.slice(lastPos));
}
}
if (hasSprit) _attrs.push('/');
return _attrs.join(' ');
if (hasSprit) _attrs += '/';
return _attrs.trim();
};
/**

View File

@@ -1,7 +1,7 @@
{
"name": "xss",
"main": "./lib/index.js",
"version": "0.0.3",
"version": "0.0.4",
"description": "XSS攻击代码过滤 Remove XSS attack vectors from user-supplied HTML",
"author": "leizongmin <leizongmin@gmail.com> (http://ucdok.com)",
"repository": {