55
66/* Utility functions */
77
8- function escape ( value : string ) : string {
9- return value
10- . replace ( / & / gm, '&' )
11- . replace ( / < / gm, '<' )
12- . replace ( / > / gm, '>' ) ;
8+ function escapeHTML ( value : string ) : string {
9+ return value . replace ( / & / gm, '&' ) . replace ( / < / gm, '<' ) . replace ( / > / gm, '>' ) ;
1310}
1411
1512function tag ( node : Node ) : string {
@@ -97,7 +94,7 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va
9794 }
9895
9996 result += `<${ tag ( node ) } ${ Array < Attr > ( )
100- . map . call ( node . attributes , attr => `${ attr . nodeName } ="${ escape ( attr . value ) } "` )
97+ . map . call ( node . attributes , attr => `${ attr . nodeName } ="${ escapeHTML ( attr . value ) . replace ( / " / g , '"' ) } "` )
10198 . join ( ' ' ) } >`;
10299 }
103100
@@ -111,7 +108,7 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va
111108
112109 while ( original . length || highlighted . length ) {
113110 let stream = selectStream ( ) ;
114- result += escape ( value . substring ( processed , stream [ 0 ] . offset ) ) ;
111+ result += escapeHTML ( value . substring ( processed , stream [ 0 ] . offset ) ) ;
115112 processed = stream [ 0 ] . offset ;
116113 if ( stream === original ) {
117114 /*
@@ -135,5 +132,6 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va
135132 render ( stream . splice ( 0 , 1 ) [ 0 ] ) ;
136133 }
137134 }
138- return result + escape ( value . substr ( processed ) ) ;
135+
136+ return result + escapeHTML ( value . substr ( processed ) ) ;
139137}
0 commit comments