@@ -287,7 +287,14 @@ function sanitizeHtml(html, options, _recursing) {
287
287
}
288
288
}
289
289
290
- if ( ! allowedAttributesMap || has ( allowedAttributesMap , name ) || allowedAttributesMap [ '*' ] ) {
290
+ const isBeingEscaped = skip && ( options . disallowedTagsMode === 'escape' || options . disallowedTagsMode === 'recursiveEscape' ) ;
291
+ const shouldPreserveEscapedAttributes = isBeingEscaped && options . preserveEscapedAttributes ;
292
+
293
+ if ( shouldPreserveEscapedAttributes ) {
294
+ each ( attribs , function ( value , a ) {
295
+ result += ' ' + a + '="' + escapeHtml ( ( value || '' ) , true ) + '"' ;
296
+ } ) ;
297
+ } else if ( ! allowedAttributesMap || has ( allowedAttributesMap , name ) || allowedAttributesMap [ '*' ] ) {
291
298
each ( attribs , function ( value , a ) {
292
299
if ( ! VALID_HTML_ATTRIBUTE_NAME . test ( a ) ) {
293
300
// This prevents part of an attribute name in the output from being
@@ -893,7 +900,8 @@ sanitizeHtml.defaults = {
893
900
allowedSchemesAppliedToAttributes : [ 'href' , 'src' , 'cite' ] ,
894
901
allowProtocolRelative : true ,
895
902
enforceHtmlBoundary : false ,
896
- parseStyleAttributes : true
903
+ parseStyleAttributes : true ,
904
+ preserveEscapedAttributes : false
897
905
} ;
898
906
899
907
sanitizeHtml . simpleTransform = function ( newTagName , newAttribs , merge ) {
0 commit comments