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

Commit ed6b9a6

Browse files
committed
refactor(ngSanitize) Remove workarounds for IE8
1 parent 2516569 commit ed6b9a6

File tree

2 files changed

+5
-53
lines changed

2 files changed

+5
-53
lines changed

src/ngSanitize/sanitize.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ function htmlParser(html, handler) {
410410
}
411411

412412
var hiddenPre=document.createElement("pre");
413-
var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/;
414413
/**
415414
* decodes all entities into regular string
416415
* @param value
@@ -419,22 +418,10 @@ var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/;
419418
function decodeEntities(value) {
420419
if (!value) { return ''; }
421420

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

440427
/**

test/ngSanitize/sanitizeSpec.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,7 @@ describe('HTML', function() {
487487
});
488488

489489
describe('decodeEntities', function() {
490-
var handler, text,
491-
origHiddenPre = window.hiddenPre;
490+
var handler, text;
492491

493492
beforeEach(function() {
494493
text = '';
@@ -503,10 +502,6 @@ describe('decodeEntities', function() {
503502
module('ngSanitize');
504503
});
505504

506-
afterEach(function() {
507-
window.hiddenPre = origHiddenPre;
508-
});
509-
510505
it('should unescape text', function() {
511506
htmlParser('a&lt;div&gt;&amp;&lt;/div&gt;c', handler)
512507
expect(text).toEqual('a<div>&</div>c');
@@ -516,34 +511,4 @@ describe('decodeEntities', function() {
516511
htmlParser(' a&amp;b ', handler)
517512
expect(text).toEqual(' a&b ');
518513
});
519-
520-
it('should use innerText if textContent is not available (IE<9)', function() {
521-
window.hiddenPre = {
522-
innerText: 'INNER_TEXT'
523-
};
524-
inject(function($sanitize) {
525-
htmlParser('<tag>text</tag>', handler);
526-
expect(text).toEqual('INNER_TEXT');
527-
});
528-
});
529-
it('should use textContent if available', function() {
530-
window.hiddenPre = {
531-
textContent: 'TEXT_CONTENT',
532-
innerText: 'INNER_TEXT'
533-
};
534-
inject(function($sanitize) {
535-
htmlParser('<tag>text</tag>', handler);
536-
expect(text).toEqual('TEXT_CONTENT');
537-
});
538-
});
539-
it('should use textContent even if empty', function() {
540-
window.hiddenPre = {
541-
textContent: '',
542-
innerText: 'INNER_TEXT'
543-
};
544-
inject(function($sanitize) {
545-
htmlParser('<tag>text</tag>', handler);
546-
expect(text).toEqual('');
547-
});
548-
});
549514
});

0 commit comments

Comments
 (0)