代码风格
This commit is contained in:
13
lib/index.js
13
lib/index.js
@@ -115,6 +115,14 @@ function noTag (text) {
|
||||
return text.replace(REGEXP_LT, '<').replace(REGEXP_GT, '>');
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤unicode字符(与REGEXP_ATTR_VALUE配合使用)
|
||||
*
|
||||
*/
|
||||
function replaceUnicode (str, code) {
|
||||
return String.fromCharCode(parseInt(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* XSS过滤对象
|
||||
*
|
||||
@@ -159,10 +167,7 @@ FilterXSS.prototype.filterAttributes = function (tagName, attrs) {
|
||||
if (value) {
|
||||
value = value.trim().replace(REGEXP_QUOTE, '"e;');
|
||||
// 转换unicode字符 及过滤不可见字符
|
||||
value = value.replace(REGEXP_ATTR_VALUE, function (str, code) {
|
||||
code = parseInt(code);
|
||||
return String.fromCharCode(code);
|
||||
});
|
||||
value = value.replace(REGEXP_ATTR_VALUE, replaceUnicode);
|
||||
var _value = '';
|
||||
for (var i = 0, len = value.length; i < len; i++) {
|
||||
_value += value.charCodeAt(i) < 32 ? ' ' : value[i];
|
||||
|
||||
Reference in New Issue
Block a user