File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ var START_TAG_REGEXP = /^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:
141
141
BEGIN_TAG_REGEXP = / ^ < / ,
142
142
BEGING_END_TAGE_REGEXP = / ^ < \s * \/ / ,
143
143
COMMENT_REGEXP = / < ! - - ( .* ?) - - > / g,
144
+ DOCTYPE_REGEXP = / < ! D O C T Y P E ( [ ^ > ] * ?) > / i,
144
145
CDATA_REGEXP = / < ! \[ C D A T A \[ ( .* ?) ] ] > / g,
145
146
URI_REGEXP = / ^ ( ( f t p | h t t p s ? ) : \/ \/ | m a i l t o : | # ) / i,
146
147
NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g; // Match everything outside of normal chars and " (quote character)
@@ -223,7 +224,14 @@ function htmlParser( html, handler ) {
223
224
html = html . substring ( index + 3 ) ;
224
225
chars = false ;
225
226
}
227
+ // DOCTYPE
228
+ } else if ( DOCTYPE_REGEXP . test ( html ) ) {
229
+ match = html . match ( DOCTYPE_REGEXP ) ;
226
230
231
+ if ( match ) {
232
+ html = html . replace ( match [ 0 ] , '' ) ;
233
+ chars = false ;
234
+ }
227
235
// end tag
228
236
} else if ( BEGING_END_TAGE_REGEXP . test ( html ) ) {
229
237
match = html . match ( END_TAG_REGEXP ) ;
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ describe('HTML', function() {
24
24
attrs : attrs ,
25
25
unary : unary
26
26
} ;
27
- // Since different browsers handle newlines differenttly we trim
27
+ // Since different browsers handle newlines differently we trim
28
28
// so that it is easier to write tests.
29
29
angular . forEach ( attrs , function ( value , key ) {
30
30
attrs [ key ] = value . replace ( / ^ \s * / , '' ) . replace ( / \s * $ / , '' )
@@ -80,6 +80,13 @@ describe('HTML', function() {
80
80
expectHTML ( 'a<SCRIPT>evil< / scrIpt >c.' ) . toEqual ( 'ac.' ) ;
81
81
} ) ;
82
82
83
+ it ( 'should remove DOCTYPE header' , function ( ) {
84
+ expectHTML ( '<!DOCTYPE html>' ) . toEqual ( '' ) ;
85
+ expectHTML ( '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n"http://www.w3.org/TR/html4/strict.dtd">' ) . toEqual ( '' ) ;
86
+ expectHTML ( 'a<!DOCTYPE html>c.' ) . toEqual ( 'ac.' ) ;
87
+ expectHTML ( 'a<!DocTyPe html>c.' ) . toEqual ( 'ac.' ) ;
88
+ } ) ;
89
+
83
90
it ( 'should remove nested script' , function ( ) {
84
91
expectHTML ( 'a< SCRIPT >A< SCRIPT >evil< / scrIpt >B< / scrIpt >c.' ) . toEqual ( 'ac.' ) ;
85
92
} ) ;
@@ -286,5 +293,6 @@ describe('HTML', function() {
286
293
} ) ;
287
294
} ) ;
288
295
296
+
289
297
} ) ;
290
298
} ) ;
You can’t perform that action at this time.
0 commit comments