优化性能
This commit is contained in:
12
lib/index.js
12
lib/index.js
@@ -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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user