This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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 @@ -135,6 +135,7 @@ var START_TAG_REGEXP = /^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:
135
135
BEGIN_TAG_REGEXP = / ^ < / ,
136
136
BEGING_END_TAGE_REGEXP = / ^ < \s * \/ / ,
137
137
COMMENT_REGEXP = / < ! - - ( .* ?) - - > / g,
138
+ DOCTYPE_REGEXP = / < ! D O C T Y P E ( [ ^ > ] * ?) > / i,
138
139
CDATA_REGEXP = / < ! \[ C D A T A \[ ( .* ?) ] ] > / g,
139
140
URI_REGEXP = / ^ ( ( f t p | h t t p s ? ) : \/ \/ | m a i l t o : | t e l : | # ) / i,
140
141
NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g; // Match everything outside of normal chars and " (quote character)
@@ -218,7 +219,14 @@ function htmlParser( html, handler ) {
218
219
html = html . substring ( index + 3 ) ;
219
220
chars = false ;
220
221
}
222
+ // DOCTYPE
223
+ } else if ( DOCTYPE_REGEXP . test ( html ) ) {
224
+ match = html . match ( DOCTYPE_REGEXP ) ;
221
225
226
+ if ( match ) {
227
+ html = html . replace ( match [ 0 ] , '' ) ;
228
+ chars = false ;
229
+ }
222
230
// end tag
223
231
} else if ( BEGING_END_TAGE_REGEXP . test ( html ) ) {
224
232
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 * $ / , '' )
@@ -112,6 +112,13 @@ describe('HTML', function() {
112
112
expectHTML ( 'a<SCRIPT>evil< / scrIpt >c.' ) . toEqual ( 'ac.' ) ;
113
113
} ) ;
114
114
115
+ it ( 'should remove DOCTYPE header' , function ( ) {
116
+ expectHTML ( '<!DOCTYPE html>' ) . toEqual ( '' ) ;
117
+ expectHTML ( '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n"http://www.w3.org/TR/html4/strict.dtd">' ) . toEqual ( '' ) ;
118
+ expectHTML ( 'a<!DOCTYPE html>c.' ) . toEqual ( 'ac.' ) ;
119
+ expectHTML ( 'a<!DocTyPe html>c.' ) . toEqual ( 'ac.' ) ;
120
+ } ) ;
121
+
115
122
it ( 'should remove nested script' , function ( ) {
116
123
expectHTML ( 'a< SCRIPT >A< SCRIPT >evil< / scrIpt >B< / scrIpt >c.' ) . toEqual ( 'ac.' ) ;
117
124
} ) ;
@@ -320,5 +327,6 @@ describe('HTML', function() {
320
327
} ) ;
321
328
} ) ;
322
329
330
+
323
331
} ) ;
324
332
} ) ;
You can’t perform that action at this time.
0 commit comments