代码风格

This commit is contained in:
Lei Zongmin
2013-05-08 16:21:46 +08:00
parent 02cf9113da
commit a5e2946f8f

View File

@@ -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, '&quote;');
// 转换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];