@@ -149,7 +149,7 @@ function sanitizeText(chars) {
149149// Regular Expressions for parsing tags and attributes
150150var SURROGATE_PAIR_REGEXP = / [ \uD800 - \uDBFF ] [ \uDC00 - \uDFFF ] / g,
151151 // Match everything outside of normal chars and " (quote character)
152- NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g;
152+ NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | ! ] ) / g;
153153
154154
155155// Good source of info about elements and attributes
@@ -236,28 +236,24 @@ function toMap(str, lowercaseKeys) {
236236 return obj ;
237237}
238238
239- var baseNode ;
239+ var inertBodyElement ;
240240( function ( window ) {
241241 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 ) {
245243 doc = window . document . implementation . createHTMLDocument ( "inert" ) ;
246- } else if ( window . ActiveXObject ) {
247- doc = new window . ActiveXObject ( "Msxml.DOMDocument" ) ;
248244 } else {
249- throw $sanitizeMinErr ( 'ddns ' , "DOMDocument not supported " ) ;
245+ throw $sanitizeMinErr ( 'noinert ' , "Can't create an inert html document " ) ;
250246 }
251247 var docElement = doc . documentElement || doc . getDocumentElement ( ) ;
252248 var bodyElements = docElement . getElementsByTagName ( 'body' ) ;
253249
254250 // usually there should be only one body element in the document, but IE doesn't have any, so we need to create one
255251 if ( bodyElements . length === 1 ) {
256- baseNode = bodyElements [ 0 ] ;
252+ inertBodyElement = bodyElements [ 0 ] ;
257253 } else {
258254 var html = doc . createElement ( 'html' ) ;
259- baseNode = doc . createElement ( 'body' ) ;
260- html . appendChild ( baseNode ) ;
255+ inertBodyElement = doc . createElement ( 'body' ) ;
256+ html . appendChild ( inertBodyElement ) ;
261257 doc . appendChild ( html ) ;
262258 }
263259} ) ( window ) ;
@@ -280,8 +276,8 @@ function htmlParser(html, handler) {
280276 } else if ( typeof html !== 'string' ) {
281277 html = '' + html ;
282278 }
283- baseNode . innerHTML = html ;
284- var node = baseNode . firstChild ;
279+ inertBodyElement . innerHTML = html ;
280+ var node = inertBodyElement . firstChild ;
285281 while ( node ) {
286282 switch ( node . nodeType ) {
287283 case 1 : // ELEMENT_NODE
@@ -290,9 +286,6 @@ function htmlParser(html, handler) {
290286 case 3 : // TEXT NODE
291287 handler . chars ( node . textContent ) ;
292288 break ;
293- case 8 : // COMMENT NODE
294- handler . comment ( node . textContent ) ;
295- break ;
296289 }
297290
298291 var nextNode ;
@@ -304,7 +297,7 @@ function htmlParser(html, handler) {
304297 if ( ! nextNode ) {
305298 while ( nextNode == null ) {
306299 node = node . parentNode ;
307- if ( node === baseNode ) break ;
300+ if ( node === inertBodyElement ) break ;
308301 nextNode = node . nextSibling ;
309302 if ( node . nodeType == 1 ) {
310303 handler . end ( node . nodeName . toLowerCase ( ) ) ;
@@ -315,8 +308,8 @@ function htmlParser(html, handler) {
315308 node = nextNode ;
316309 }
317310
318- while ( node = baseNode . firstChild ) {
319- baseNode . removeChild ( node ) ;
311+ while ( node = inertBodyElement . firstChild ) {
312+ inertBodyElement . removeChild ( node ) ;
320313 }
321314}
322315
@@ -329,20 +322,6 @@ function attrToMap(attrs) {
329322 return map ;
330323}
331324
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- }
346325
347326/**
348327 * Escapes all potentially dangerous characters, so that the
@@ -368,7 +347,7 @@ function encodeEntities(value) {
368347
369348/**
370349 * 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
372351 * @returns {object } in the form of {
373352 * start: function(tag, attrs) {},
374353 * end: function(tag) {},
@@ -405,7 +384,7 @@ function htmlSanitizeWriter(buf, uriValidator) {
405384 } ,
406385 end : function ( tag ) {
407386 tag = angular . lowercase ( tag ) ;
408- if ( ! ignore && validElements [ tag ] === true ) {
387+ if ( ! ignore && validElements [ tag ] === true && voidElements [ tag ] !== true ) {
409388 out ( '</' ) ;
410389 out ( tag ) ;
411390 out ( '>' ) ;
0 commit comments