Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 27fcca9

Browse files
realitykingpetebacondarwin
authored andcommitted
refactor(ngSanitize): remove workarounds for IE8
Closes #10758
1 parent 2015ed2 commit 27fcca9

File tree

2 files changed

+5
-53
lines changed

2 files changed

+5
-53
lines changed

src/ngSanitize/sanitize.js

+4-17
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ function htmlParser(html, handler) {
413413
}
414414

415415
var hiddenPre=document.createElement("pre");
416-
var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/;
417416
/**
418417
* decodes all entities into regular string
419418
* @param value
@@ -422,22 +421,10 @@ var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/;
422421
function decodeEntities(value) {
423422
if (!value) { return ''; }
424423

425-
// Note: IE8 does not preserve spaces at the start/end of innerHTML
426-
// so we must capture them and reattach them afterward
427-
var parts = spaceRe.exec(value);
428-
var spaceBefore = parts[1];
429-
var spaceAfter = parts[3];
430-
var content = parts[2];
431-
if (content) {
432-
hiddenPre.innerHTML=content.replace(/</g,"&lt;");
433-
// innerText depends on styling as it doesn't display hidden elements.
434-
// Therefore, it's better to use textContent not to cause unnecessary
435-
// reflows. However, IE<9 don't support textContent so the innerText
436-
// fallback is necessary.
437-
content = 'textContent' in hiddenPre ?
438-
hiddenPre.textContent : hiddenPre.innerText;
439-
}
440-
return spaceBefore + content + spaceAfter;
424+
hiddenPre.innerHTML = value.replace(/</g,"&lt;");
425+
// innerText depends on styling as it doesn't display hidden elements.
426+
// Therefore, it's better to use textContent not to cause unnecessary reflows.
427+
return hiddenPre.textContent;
441428
}
442429

443430
/**

test/ngSanitize/sanitizeSpec.js

+1-36
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,7 @@ describe('HTML', function() {
495495
});
496496

497497
describe('decodeEntities', function() {
498-
var handler, text,
499-
origHiddenPre = window.hiddenPre;
498+
var handler, text;
500499

501500
beforeEach(function() {
502501
text = '';
@@ -511,10 +510,6 @@ describe('decodeEntities', function() {
511510
module('ngSanitize');
512511
});
513512

514-
afterEach(function() {
515-
window.hiddenPre = origHiddenPre;
516-
});
517-
518513
it('should unescape text', function() {
519514
htmlParser('a&lt;div&gt;&amp;&lt;/div&gt;c', handler);
520515
expect(text).toEqual('a<div>&</div>c');
@@ -524,34 +519,4 @@ describe('decodeEntities', function() {
524519
htmlParser(' a&amp;b ', handler);
525520
expect(text).toEqual(' a&b ');
526521
});
527-
528-
it('should use innerText if textContent is not available (IE<9)', function() {
529-
window.hiddenPre = {
530-
innerText: 'INNER_TEXT'
531-
};
532-
inject(function($sanitize) {
533-
htmlParser('<tag>text</tag>', handler);
534-
expect(text).toEqual('INNER_TEXT');
535-
});
536-
});
537-
it('should use textContent if available', function() {
538-
window.hiddenPre = {
539-
textContent: 'TEXT_CONTENT',
540-
innerText: 'INNER_TEXT'
541-
};
542-
inject(function($sanitize) {
543-
htmlParser('<tag>text</tag>', handler);
544-
expect(text).toEqual('TEXT_CONTENT');
545-
});
546-
});
547-
it('should use textContent even if empty', function() {
548-
window.hiddenPre = {
549-
textContent: '',
550-
innerText: 'INNER_TEXT'
551-
};
552-
inject(function($sanitize) {
553-
htmlParser('<tag>text</tag>', handler);
554-
expect(text).toEqual('');
555-
});
556-
});
557522
});

0 commit comments

Comments
 (0)