@@ -149,7 +149,7 @@ function sanitizeText(chars) {
149
149
// Regular Expressions for parsing tags and attributes
150
150
var SURROGATE_PAIR_REGEXP = / [ \uD800 - \uDBFF ] [ \uDC00 - \uDFFF ] / g,
151
151
// Match everything outside of normal chars and " (quote character)
152
- NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g;
152
+ NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | ! ] ) / g;
153
153
154
154
155
155
// Good source of info about elements and attributes
@@ -236,28 +236,24 @@ function toMap(str, lowercaseKeys) {
236
236
return obj ;
237
237
}
238
238
239
- var baseNode ;
239
+ var inertBodyElement ;
240
240
( function ( window ) {
241
241
var doc ;
242
- if ( window . DOMDocument ) {
243
- doc = new window . DOMDocument ( ) ;
244
- } else if ( window . document && window . document . implementation ) {
242
+ if ( window . document && window . document . implementation ) {
245
243
doc = window . document . implementation . createHTMLDocument ( "inert" ) ;
246
- } else if ( window . ActiveXObject ) {
247
- doc = new window . ActiveXObject ( "Msxml.DOMDocument" ) ;
248
244
} else {
249
- throw $sanitizeMinErr ( 'ddns ' , "DOMDocument not supported " ) ;
245
+ throw $sanitizeMinErr ( 'noinert ' , "Can't create an inert html document " ) ;
250
246
}
251
247
var docElement = doc . documentElement || doc . getDocumentElement ( ) ;
252
248
var bodyElements = docElement . getElementsByTagName ( 'body' ) ;
253
249
254
250
// usually there should be only one body element in the document, but IE doesn't have any, so we need to create one
255
251
if ( bodyElements . length === 1 ) {
256
- baseNode = bodyElements [ 0 ] ;
252
+ inertBodyElement = bodyElements [ 0 ] ;
257
253
} else {
258
254
var html = doc . createElement ( 'html' ) ;
259
- baseNode = doc . createElement ( 'body' ) ;
260
- html . appendChild ( baseNode ) ;
255
+ inertBodyElement = doc . createElement ( 'body' ) ;
256
+ html . appendChild ( inertBodyElement ) ;
261
257
doc . appendChild ( html ) ;
262
258
}
263
259
} ) ( window ) ;
@@ -280,8 +276,8 @@ function htmlParser(html, handler) {
280
276
} else if ( typeof html !== 'string' ) {
281
277
html = '' + html ;
282
278
}
283
- baseNode . innerHTML = html ;
284
- var node = baseNode . firstChild ;
279
+ inertBodyElement . innerHTML = html ;
280
+ var node = inertBodyElement . firstChild ;
285
281
while ( node ) {
286
282
switch ( node . nodeType ) {
287
283
case 1 : // ELEMENT_NODE
@@ -290,9 +286,6 @@ function htmlParser(html, handler) {
290
286
case 3 : // TEXT NODE
291
287
handler . chars ( node . textContent ) ;
292
288
break ;
293
- case 8 : // COMMENT NODE
294
- handler . comment ( node . textContent ) ;
295
- break ;
296
289
}
297
290
298
291
var nextNode ;
@@ -304,7 +297,7 @@ function htmlParser(html, handler) {
304
297
if ( ! nextNode ) {
305
298
while ( nextNode == null ) {
306
299
node = node . parentNode ;
307
- if ( node === baseNode ) break ;
300
+ if ( node === inertBodyElement ) break ;
308
301
nextNode = node . nextSibling ;
309
302
if ( node . nodeType == 1 ) {
310
303
handler . end ( node . nodeName . toLowerCase ( ) ) ;
@@ -315,8 +308,8 @@ function htmlParser(html, handler) {
315
308
node = nextNode ;
316
309
}
317
310
318
- while ( node = baseNode . firstChild ) {
319
- baseNode . removeChild ( node ) ;
311
+ while ( node = inertBodyElement . firstChild ) {
312
+ inertBodyElement . removeChild ( node ) ;
320
313
}
321
314
}
322
315
@@ -329,20 +322,6 @@ function attrToMap(attrs) {
329
322
return map ;
330
323
}
331
324
332
- var hiddenPre = document . createElement ( "pre" ) ;
333
- /**
334
- * decodes all entities into regular string
335
- * @param value
336
- * @returns {string } A string with decoded entities.
337
- */
338
- function decodeEntities ( value ) {
339
- if ( ! value ) { return '' ; }
340
-
341
- hiddenPre . innerHTML = value . replace ( / < / g, "<" ) ;
342
- // innerText depends on styling as it doesn't display hidden elements.
343
- // Therefore, it's better to use textContent not to cause unnecessary reflows.
344
- return hiddenPre . textContent ;
345
- }
346
325
347
326
/**
348
327
* Escapes all potentially dangerous characters, so that the
@@ -368,7 +347,7 @@ function encodeEntities(value) {
368
347
369
348
/**
370
349
* create an HTML/XML writer which writes to buffer
371
- * @param {Array } buf use buf.jain ('') to get out sanitized html string
350
+ * @param {Array } buf use buf.join ('') to get out sanitized html string
372
351
* @returns {object } in the form of {
373
352
* start: function(tag, attrs) {},
374
353
* end: function(tag) {},
@@ -405,7 +384,7 @@ function htmlSanitizeWriter(buf, uriValidator) {
405
384
} ,
406
385
end : function ( tag ) {
407
386
tag = angular . lowercase ( tag ) ;
408
- if ( ! ignore && validElements [ tag ] === true ) {
387
+ if ( ! ignore && validElements [ tag ] === true && voidElements [ tag ] !== true ) {
409
388
out ( '</' ) ;
410
389
out ( tag ) ;
411
390
out ( '>' ) ;
0 commit comments