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

fix($sce): do not assume $document[0] exists #9663

Merged
merged 3 commits into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/sce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
6 changes: 0 additions & 6 deletions src/ngScenario/browserTrigger.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
'use strict';

(function() {
/**
* documentMode is an IE-only property
* http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
*/
var msie = document.documentMode;

/**
* Triggers a browser event. Attempts to choose the right event if one is
* not specified.
Expand Down
15 changes: 0 additions & 15 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,21 +1249,6 @@ describe('angular', function() {
});
});

describe('msie UA parsing', function() {
if (/ Trident\/.*; rv:/.test(window.navigator.userAgent)) {
it('should fail when the Trident and the rv versions disagree for IE11+', function() {
// When this test fails, we can think about whether we want to use the version from the
// Trident token in the UA string or stick with the version from rv: as we currently do.
// Refer https://github.com/angular/angular.js/pull/3758#issuecomment-23529245 for the
// discussion.
var UA = window.navigator.userAgent;
var tridentVersion = parseInt((/Trident\/(\d+)/.exec(UA) || [])[1], 10) + 4;
var rvVersion = parseInt((/Trident\/.*; rv:(\d+)/.exec(UA) || [])[1], 10);
expect(tridentVersion).toBe(rvVersion);
});
}
});

describe('isElement', function() {
it('should return a boolean value', inject(function($compile, $document, $rootScope) {
var element = $compile('<p>Hello, world!</p>')($rootScope),
Expand Down
15 changes: 12 additions & 3 deletions test/ng/sceSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me and is not much more ugly that the bit you've removed :-)

module(function($provide) {
$provide.value('$document', [{
documentMode: documentMode
}]);
$provide.value('$sceDelegate', {trustAs: null, valueOf: null, getTrusted: null});
});

Expand Down
5 changes: 5 additions & 0 deletions test/ng/windowSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});