fix($sce): use msie instead of $document[0].documentMode

this is important so that people can mock $window without having to add stuff that angular uses internally into it

Closes #9661
This commit is contained in:
Shahar Talmi
2014-10-17 15:52:00 +03:00
parent c2edef86c5
commit 45252c3a54
3 changed files with 18 additions and 4 deletions

View File

@@ -722,7 +722,7 @@ function $SceProvider() {
$document, $parse, $sceDelegate) {
// Prereq: Ensure that we're not running in IE<11 quirks mode. In that mode, IE < 11 allow
// the "expression(javascript expression)" syntax which is insecure.
if (enabled && $document[0].documentMode < 8) {
if (enabled && msie < 8) {
throw $sceMinErr('iequirks',
'Strict Contextual Escaping does not support Internet Explorer version < 11 in quirks ' +
'mode. You can fix this by adding the text <!doctype html> to the top of your HTML ' +

View File

@@ -27,11 +27,20 @@ describe('SCE', function() {
});
describe('IE<11 quirks mode', function() {
/* global msie: true */
var msieBackup;
beforeEach(function() {
msieBackup = msie;
});
afterEach(function() {
msie = msieBackup;
});
function runTest(enabled, documentMode, expectException) {
msie = documentMode;
module(function($provide) {
$provide.value('$document', [{
documentMode: documentMode
}]);
$provide.value('$sceDelegate', {trustAs: null, valueOf: null, getTrusted: null});
});

View File

@@ -4,4 +4,9 @@ describe('$window', function() {
it("should inject $window", inject(function($window) {
expect($window).toBe(window);
}));
it('should be able to mock $window without errors', function() {
module({$window: {}});
inject(['$sce', angular.noop]);
});
});