@@ -168,11 +168,13 @@ var START_TAG_REGEXP =
168
168
BEGIN_TAG_REGEXP = / ^ < / ,
169
169
BEGING_END_TAGE_REGEXP = / ^ < \/ / ,
170
170
COMMENT_REGEXP = / < ! - - ( .* ?) - - > / g,
171
+ SINGLE_COMMENT_REGEXP = / ( ^ < ! - - .* ?- - > ) / ,
171
172
DOCTYPE_REGEXP = / < ! D O C T Y P E ( [ ^ > ] * ?) > / i,
172
173
CDATA_REGEXP = / < ! \[ C D A T A \[ ( .* ?) ] ] > / g,
173
174
SURROGATE_PAIR_REGEXP = / [ \uD800 - \uDBFF ] [ \uDC00 - \uDFFF ] / g,
174
175
// Match everything outside of normal chars and " (quote character)
175
- NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g;
176
+ NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g,
177
+ WHITE_SPACE_REGEXP = / ^ ( \s + ) / ;
176
178
177
179
178
180
// Good source of info about elements and attributes
@@ -288,14 +290,23 @@ function htmlParser(html, handler) {
288
290
// Make sure we're not in a script or style element
289
291
if ( ! stack . last ( ) || ! specialElements [ stack . last ( ) ] ) {
290
292
291
- // Comment
292
- if ( html . indexOf ( "<!--" ) === 0 ) {
293
- // comments containing -- are not allowed unless they terminate the comment
294
- index = html . indexOf ( "--" , 4 ) ;
293
+ // White space
294
+ if ( WHITE_SPACE_REGEXP . test ( html ) ) {
295
+ match = html . match ( WHITE_SPACE_REGEXP ) ;
295
296
296
- if ( index >= 0 && html . lastIndexOf ( "-->" , index ) === index ) {
297
- if ( handler . comment ) handler . comment ( html . substring ( 4 , index ) ) ;
298
- html = html . substring ( index + 3 ) ;
297
+ if ( match ) {
298
+ var mat = match [ 0 ] ;
299
+ if ( handler . whitespace ) handler . whitespace ( match [ 0 ] ) ;
300
+ html = html . replace ( match [ 0 ] , '' ) ;
301
+ chars = false ;
302
+ }
303
+ //Comment
304
+ } else if ( SINGLE_COMMENT_REGEXP . test ( html ) ) {
305
+ match = html . match ( SINGLE_COMMENT_REGEXP ) ;
306
+
307
+ if ( match ) {
308
+ if ( handler . comment ) handler . comment ( match [ 1 ] ) ;
309
+ html = html . replace ( match [ 0 ] , '' ) ;
299
310
chars = false ;
300
311
}
301
312
// DOCTYPE
@@ -587,6 +598,12 @@ function htmlSanitizeWriter(buf, uriValidator) {
587
598
out ( unary ? '/>' : '>' ) ;
588
599
}
589
600
} ,
601
+ comment : function ( com ) {
602
+ out ( com ) ;
603
+ } ,
604
+ whitespace : function ( ws ) {
605
+ out ( encodeEntities ( ws ) ) ;
606
+ } ,
590
607
end : function ( tag ) {
591
608
tag = angular . lowercase ( tag ) ;
592
609
if ( ! ignore && validElements [ tag ] === true ) {
0 commit comments