6
6
*/
7
7
8
8
var FilterCSS = require ( 'cssfilter' ) . FilterCSS ;
9
+ var getDefaultCSSWhiteList = require ( 'cssfilter' ) . getDefaultWhiteList ;
9
10
var _ = require ( './util' ) ;
10
11
11
12
// 默认白名单
@@ -147,7 +148,6 @@ function escapeHtml (html) {
147
148
* @return {String }
148
149
*/
149
150
function safeAttrValue ( tag , name , value , cssFilter ) {
150
- cssFilter = cssFilter || defaultCSSFilter ;
151
151
// 转换为友好的属性值,再做判断
152
152
value = friendlyAttrValue ( value ) ;
153
153
@@ -189,7 +189,10 @@ function safeAttrValue (tag, name, value, cssFilter) {
189
189
return '' ;
190
190
}
191
191
}
192
- value = cssFilter . process ( value ) ;
192
+ if ( cssFilter !== false ) {
193
+ cssFilter = cssFilter || defaultCSSFilter ;
194
+ value = cssFilter . process ( value ) ;
195
+ }
193
196
}
194
197
195
198
// 输出时需要转义<>"
@@ -408,7 +411,7 @@ exports.StripTagBody = StripTagBody;
408
411
exports . stripCommentTag = stripCommentTag ;
409
412
exports . stripBlankChar = stripBlankChar ;
410
413
exports . cssFilter = defaultCSSFilter ;
411
-
414
+ exports . getDefaultCSSWhiteList = getDefaultCSSWhiteList ;
412
415
413
416
} , { "./util" :4 , "cssfilter" :8 } ] , 2 :[ function ( require , module , exports ) {
414
417
/**
@@ -774,7 +777,7 @@ function getAttrs (html) {
774
777
* 选项:whiteList, onTag, onTagAttr, onIgnoreTag,
775
778
* onIgnoreTagAttr, safeAttrValue, escapeHtml
776
779
* stripIgnoreTagBody, allowCommentTag, stripBlankChar
777
- * css{whiteList, onAttr, onIgnoreAttr}
780
+ * css{whiteList, onAttr, onIgnoreAttr} css=false表示禁用cssfilter
778
781
*/
779
782
function FilterXSS ( options ) {
780
783
options = options || { } ;
@@ -793,10 +796,14 @@ function FilterXSS (options) {
793
796
options . onIgnoreTagAttr = options . onIgnoreTagAttr || DEFAULT . onIgnoreTagAttr ;
794
797
options . safeAttrValue = options . safeAttrValue || DEFAULT . safeAttrValue ;
795
798
options . escapeHtml = options . escapeHtml || DEFAULT . escapeHtml ;
796
- options . css = options . css || { } ;
797
799
this . options = options ;
798
800
799
- this . cssFilter = new FilterCSS ( options . css ) ;
801
+ if ( options . css === false ) {
802
+ this . cssFilter = false ;
803
+ } else {
804
+ options . css = options . css || { } ;
805
+ this . cssFilter = new FilterCSS ( options . css ) ;
806
+ }
800
807
}
801
808
802
809
/**
0 commit comments