From d2148fe36c30b6f15066d8d24f3942882e4e7498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Thu, 22 Jan 2015 17:03:20 +0100 Subject: [PATCH 1/2] test(ngSanitize): Add tests for decodeEntities --- test/ngSanitize/sanitizeSpec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/ngSanitize/sanitizeSpec.js b/test/ngSanitize/sanitizeSpec.js index 2642bdf6fde9..e53315e4bc9c 100644 --- a/test/ngSanitize/sanitizeSpec.js +++ b/test/ngSanitize/sanitizeSpec.js @@ -514,6 +514,16 @@ describe('decodeEntities', function() { afterEach(function() { window.hiddenPre = origHiddenPre; }); + + it('should unescape text', function() { + htmlParser('a<div>&</div>c', handler) + expect(text).toEqual('a
&
c'); + }); + + it('should preserve whitespace', function() { + htmlParser(' a&b ', handler) + expect(text).toEqual(' a&b '); + }); it('should use innerText if textContent is not available (IE<9)', function() { window.hiddenPre = { From 12db51a3c802015a5a96d8e1de734daac3a32e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Thu, 15 Jan 2015 01:44:59 +0100 Subject: [PATCH 2/2] refactor(ngSanitize): Remove workarounds for IE8 --- src/ngSanitize/sanitize.js | 21 ++++--------------- test/ngSanitize/sanitizeSpec.js | 37 +-------------------------------- 2 files changed, 5 insertions(+), 53 deletions(-) diff --git a/src/ngSanitize/sanitize.js b/src/ngSanitize/sanitize.js index 50210fea05c1..a23fc1b12e3f 100644 --- a/src/ngSanitize/sanitize.js +++ b/src/ngSanitize/sanitize.js @@ -413,7 +413,6 @@ function htmlParser(html, handler) { } var hiddenPre=document.createElement("pre"); -var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/; /** * decodes all entities into regular string * @param value @@ -422,22 +421,10 @@ var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/; function decodeEntities(value) { if (!value) { return ''; } - // Note: IE8 does not preserve spaces at the start/end of innerHTML - // so we must capture them and reattach them afterward - var parts = spaceRe.exec(value); - var spaceBefore = parts[1]; - var spaceAfter = parts[3]; - var content = parts[2]; - if (content) { - hiddenPre.innerHTML=content.replace(/&c'); @@ -524,34 +519,4 @@ describe('decodeEntities', function() { htmlParser(' a&b ', handler) expect(text).toEqual(' a&b '); }); - - it('should use innerText if textContent is not available (IE<9)', function() { - window.hiddenPre = { - innerText: 'INNER_TEXT' - }; - inject(function($sanitize) { - htmlParser('text', handler); - expect(text).toEqual('INNER_TEXT'); - }); - }); - it('should use textContent if available', function() { - window.hiddenPre = { - textContent: 'TEXT_CONTENT', - innerText: 'INNER_TEXT' - }; - inject(function($sanitize) { - htmlParser('text', handler); - expect(text).toEqual('TEXT_CONTENT'); - }); - }); - it('should use textContent even if empty', function() { - window.hiddenPre = { - textContent: '', - innerText: 'INNER_TEXT' - }; - inject(function($sanitize) { - htmlParser('text', handler); - expect(text).toEqual(''); - }); - }); });