diff --git a/src/ngSanitize/sanitize.js b/src/ngSanitize/sanitize.js index 5d378b02cac3..e669e77a63b1 100644 --- a/src/ngSanitize/sanitize.js +++ b/src/ngSanitize/sanitize.js @@ -360,25 +360,27 @@ function htmlParser( html, handler ) { } } +var hiddenPre=document.createElement("pre"); +var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/; /** * decodes all entities into regular string * @param value * @returns {string} A string with decoded entities. */ -var hiddenPre=document.createElement("pre"); function decodeEntities(value) { - if (!value) { - return ''; - } + if (!value) { return ''; } + // Note: IE8 does not preserve spaces at the start/end of innerHTML - var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/; + // so we must capture them and reattach them afterward var parts = spaceRe.exec(value); - parts[0] = ''; - if (parts[2]) { - hiddenPre.innerHTML=parts[2].replace(/