@@ -41,7 +41,7 @@ class CssSanitizer {
41
41
constructor (
42
42
private readonly propertyAllowlist : ReadonlySet < string > ,
43
43
private readonly functionAllowlist : ReadonlySet < string > ,
44
- private readonly resourceUrlPolicy : ResourceUrlPolicy ,
44
+ private readonly resourceUrlPolicy : ResourceUrlPolicy | undefined ,
45
45
private readonly allowKeyframes : boolean ,
46
46
private readonly propertyDiscarders : PropertyDiscarder [ ] ,
47
47
) { }
@@ -142,18 +142,21 @@ class CssSanitizer {
142
142
return null ;
143
143
}
144
144
const url = nextToken . value ;
145
- const sanitizedUrl = this . resourceUrlPolicy ( parseUrl ( url ) , {
146
- type : calledFromStyleTag
147
- ? ResourceUrlPolicyHintsType . STYLE_TAG
148
- : ResourceUrlPolicyHintsType . STYLE_ATTRIBUTE ,
149
- propertyName,
150
- } ) ;
151
- if ( ! sanitizedUrl ) {
145
+ let parsedUrl : URL | null = parseUrl ( url ) ;
146
+ if ( this . resourceUrlPolicy ) {
147
+ parsedUrl = this . resourceUrlPolicy ( parsedUrl , {
148
+ type : calledFromStyleTag
149
+ ? ResourceUrlPolicyHintsType . STYLE_TAG
150
+ : ResourceUrlPolicyHintsType . STYLE_ATTRIBUTE ,
151
+ propertyName,
152
+ } ) ;
153
+ }
154
+ if ( ! parsedUrl ) {
152
155
return null ;
153
156
}
154
157
tokens [ i + 1 ] = {
155
158
tokenKind : CssTokenKind . STRING ,
156
- value : sanitizedUrl . toString ( ) ,
159
+ value : parsedUrl . toString ( ) ,
157
160
} ;
158
161
159
162
// Skip the string token.
@@ -293,7 +296,7 @@ export function sanitizeStyleTag(
293
296
cssText : string ,
294
297
propertyAllowlist : ReadonlySet < string > ,
295
298
functionAllowlist : ReadonlySet < string > ,
296
- resourceUrlPolicy : ResourceUrlPolicy ,
299
+ resourceUrlPolicy : ResourceUrlPolicy | undefined ,
297
300
allowKeyframes : boolean ,
298
301
propertyDiscarders : PropertyDiscarder [ ] ,
299
302
) : string {
@@ -316,7 +319,7 @@ export function sanitizeStyleAttribute(
316
319
cssText : string ,
317
320
propertyAllowlist : ReadonlySet < string > ,
318
321
functionAllowlist : ReadonlySet < string > ,
319
- resourceUrlPolicy : ResourceUrlPolicy ,
322
+ resourceUrlPolicy : ResourceUrlPolicy | undefined ,
320
323
propertyDiscarders : PropertyDiscarder [ ] ,
321
324
) : string {
322
325
return new CssSanitizer (
0 commit comments