@@ -2788,7 +2788,6 @@ common.sanitizeFilename = (filename, replacement = "") => {
2788
2788
* @returns {string } sanitizedHTML - sanitized html content
2789
2789
*/
2790
2790
common . sanitizeHTML = ( html ) => {
2791
-
2792
2791
const whiteList = {
2793
2792
a : [ "target" , "title" ] ,
2794
2793
abbr : [ "title" ] ,
@@ -2887,20 +2886,34 @@ common.sanitizeHTML = (html) => {
2887
2886
}
2888
2887
2889
2888
const attributesRegex = / \b ( \w + ) = [ " ' ] ( [ ^ " ' ] * ) [ " ' ] / g;
2890
-
2889
+ var doubleQuote = '"' ,
2890
+ singleQuote = "'" ;
2891
2891
let matches ;
2892
2892
let filteredAttributes = [ ] ;
2893
2893
let allowedAttributes = Object . getOwnPropertyDescriptor ( whiteList , tagName ) . value ;
2894
2894
let tagHasAttributes = false ;
2895
2895
while ( ( matches = attributesRegex . exec ( tag ) ) !== null ) {
2896
2896
tagHasAttributes = true ;
2897
+ let fullAttribute = matches [ 0 ] ;
2897
2898
let attributeName = matches [ 1 ] ;
2898
2899
let attributeValue = matches [ 2 ] ;
2899
2900
if ( allowedAttributes . indexOf ( attributeName ) > - 1 ) {
2900
- filteredAttributes . push ( `${ attributeName } ="${ attributeValue } "` ) ;
2901
+
2902
+ var attributeValueStart = fullAttribute . indexOf ( attributeValue ) ;
2903
+ if ( attributeValueStart >= 1 ) {
2904
+ var attributeWithQuote = fullAttribute . substring ( attributeValueStart - 1 ) ;
2905
+ if ( attributeWithQuote . indexOf ( doubleQuote ) === 0 ) {
2906
+ filteredAttributes . push ( `${ attributeName } =${ doubleQuote } ${ attributeValue } ${ doubleQuote } ` ) ;
2907
+ }
2908
+ else if ( ( attributeWithQuote . indexOf ( singleQuote ) === 0 ) ) {
2909
+ filteredAttributes . push ( `${ attributeName } =${ singleQuote } ${ attributeValue } ${ singleQuote } ` ) ;
2910
+ }
2911
+ else { //no quote
2912
+ filteredAttributes . push ( `${ attributeName } =${ attributeValue } ` ) ;
2913
+ }
2914
+ }
2901
2915
}
2902
2916
}
2903
- console . log ( "attributes" , filteredAttributes ) ;
2904
2917
if ( ! tagHasAttributes ) { //closing tag or tag without any attributes
2905
2918
return tag ;
2906
2919
}
0 commit comments