fix($sanitize): reduce stack height in IE <= 11
Update Internet Explorer-only helper function stripCustomNsAttrs to be less recursive. Reduce stack height of function causing out of stack space error. Closes #14928 Closes #15030
This commit is contained in:
+16
-17
@@ -499,27 +499,26 @@ function $SanitizeProvider() {
|
||||
* @param node Root element to process
|
||||
*/
|
||||
function stripCustomNsAttrs(node) {
|
||||
if (node.nodeType === window.Node.ELEMENT_NODE) {
|
||||
var attrs = node.attributes;
|
||||
for (var i = 0, l = attrs.length; i < l; i++) {
|
||||
var attrNode = attrs[i];
|
||||
var attrName = attrNode.name.toLowerCase();
|
||||
if (attrName === 'xmlns:ns1' || attrName.lastIndexOf('ns1:', 0) === 0) {
|
||||
node.removeAttributeNode(attrNode);
|
||||
i--;
|
||||
l--;
|
||||
while (node) {
|
||||
if (node.nodeType === window.Node.ELEMENT_NODE) {
|
||||
var attrs = node.attributes;
|
||||
for (var i = 0, l = attrs.length; i < l; i++) {
|
||||
var attrNode = attrs[i];
|
||||
var attrName = attrNode.name.toLowerCase();
|
||||
if (attrName === 'xmlns:ns1' || attrName.lastIndexOf('ns1:', 0) === 0) {
|
||||
node.removeAttributeNode(attrNode);
|
||||
i--;
|
||||
l--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var nextNode = node.firstChild;
|
||||
if (nextNode) {
|
||||
stripCustomNsAttrs(nextNode);
|
||||
}
|
||||
var nextNode = node.firstChild;
|
||||
if (nextNode) {
|
||||
stripCustomNsAttrs(nextNode);
|
||||
}
|
||||
|
||||
nextNode = node.nextSibling;
|
||||
if (nextNode) {
|
||||
stripCustomNsAttrs(nextNode);
|
||||
node = node.nextSibling;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,17 @@ describe('HTML', function() {
|
||||
expectHTML('a<div style="abc">b</div>c').toEqual('a<div>b</div>c');
|
||||
});
|
||||
|
||||
it('should handle large datasets', function() {
|
||||
// Large is non-trivial to quantify, but handling ~100,000 should be sufficient for most purposes.
|
||||
var largeNumber = 17; // 2^17 = 131,072
|
||||
var result = '<div>b</div>';
|
||||
// Ideally we would use repeat, but that isn't supported in IE.
|
||||
for (var i = 0; i < largeNumber; i++) {
|
||||
result += result;
|
||||
}
|
||||
expectHTML('a' + result + 'c').toEqual('a' + result + 'c');
|
||||
});
|
||||
|
||||
it('should remove style', function() {
|
||||
expectHTML('a<STyle>evil</stYle>c.').toEqual('ac.');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user