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

Commit 427ee93

Browse files
committed
fix(core): parse IE11 UA string correctly
It's great that IE11 wants to be compatible enough that it doesn't want to be special cased and treated differently. However, as long as one has to have a different code path for IE than for the other supported browsers, we still need to detect and special case it. For instance, our URL parsing code still needs the same workaround the we used for IE10. We still see the same Access denied / TypeError exceptions when setting certain values. FYI, Angular doesn't generally blindly test for IE – we also check the version number. Thanks to modern.ie for the free IE11 test VM. Closes #3682
1 parent 366c0e0 commit 427ee93

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

src/Angular.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if ('i' !== 'I'.toLowerCase()) {
5858

5959

6060
var /** holds major version number for IE or NaN for real browsers */
61-
msie = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]),
61+
msie,
6262
jqLite, // delay binding since jQuery could be loaded after us.
6363
jQuery, // delay binding
6464
slice = [].slice,
@@ -74,6 +74,16 @@ var /** holds major version number for IE or NaN for real browsers */
7474
nodeName_,
7575
uid = ['0', '0', '0'];
7676

77+
/**
78+
* IE 11 changed the format of the UserAgent string.
79+
* See http://msdn.microsoft.com/en-us/library/ms537503.aspx
80+
*/
81+
msie = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]);
82+
if (isNaN(msie)) {
83+
msie = int((/trident\/.*; rv:(\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]);
84+
}
85+
86+
7787
/**
7888
* @private
7989
* @param {*} obj

src/ng/urlUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function $$UrlUtilsProvider() {
7575
*/
7676
function resolve(url, parse) {
7777
var href = url;
78-
if (msie) {
78+
if (msie <= 11) {
7979
// Normalize before parse. Refer Implementation Notes on why this is
8080
// done in two steps on IE.
8181
urlParsingNode.setAttribute("href", href);

test/AngularSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -1003,4 +1003,19 @@ describe('angular', function() {
10031003
});
10041004
});
10051005

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

test/ng/compileSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@ describe('$compile', function() {
28972897
}));
28982898

28992899

2900-
// Fails on IE < 10 with "TypeError: Access is denied" when trying to set img[src]
2900+
// Fails on IE <= 10 with "TypeError: Access is denied" when trying to set img[src]
29012901
if (!msie || msie > 10) {
29022902
it('should sanitize mailto: urls', inject(function($compile, $rootScope) {
29032903
element = $compile('<img src="{{testUrl}}"></a>')($rootScope);
@@ -3008,9 +3008,9 @@ describe('$compile', function() {
30083008
inject(function($compile, $rootScope) {
30093009
element = $compile('<img src="{{testUrl}}"></img>')($rootScope);
30103010

3011-
// Fails on IE < 10 with "TypeError: Object doesn't support this property or method" when
3011+
// Fails on IE <= 11 with "TypeError: Object doesn't support this property or method" when
30123012
// trying to set img[src]
3013-
if (!msie || msie > 10) {
3013+
if (!msie || msie > 11) {
30143014
$rootScope.testUrl = "javascript:doEvilStuff()";
30153015
$rootScope.$apply();
30163016
expect(element.attr('src')).toBe('javascript:doEvilStuff()');

test/ng/snifferSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('$sniffer', function() {
112112
else if(/firefox/i.test(ua)) {
113113
expectedPrefix = 'Moz';
114114
}
115-
else if(/ie/i.test(ua)) {
115+
else if(/ie/i.test(ua) || /trident/i.test(ua)) {
116116
expectedPrefix = 'Ms';
117117
}
118118
else if(/opera/i.test(ua)) {

0 commit comments

Comments
 (0)