Skip to content

Commit

Permalink
chore($sniffer): Remove $sniffer.msie & $sniffer.msieDocumentMode
Browse files Browse the repository at this point in the history
Since msie is now set to document.documentMode, it's not necessary to keep
the documentMode in a separate property.

Also, msie is a variable global to Angular source so there's no need to
replicate it in $sniffer.

Closes angulargh-9496
  • Loading branch information
mgol authored and IgorMinar committed Oct 9, 2014
1 parent 2435e2b commit 64241a5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 34 deletions.
8 changes: 4 additions & 4 deletions docs/content/error/$sce/iequirks.ngdoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@ngdoc error
@name $sce:iequirks
@fullName IE8 in quirks mode is unsupported
@fullName IE<11 in quirks mode is unsupported
@description

This error occurs when you are using AngularJS with {@link ng.$sce Strict Contextual Escaping (SCE)} mode enabled (the default) on IE8 or lower in quirks mode.
This error occurs when you are using AngularJS with {@link ng.$sce Strict Contextual Escaping (SCE)} mode enabled (the default) on IE10 or lower in quirks mode.

In this mode, IE8 allows one to execute arbitrary javascript by the use of the `expression()` syntax and is not supported.
In this mode, IE<11 allow one to execute arbitrary javascript by the use of the `expression()` syntax and is not supported.
Refer
[MSDN Blogs > IEBlog > Ending Expressions](http://blogs.msdn.com/b/ie/archive/2008/10/16/ending-expressions.aspx)
[CSS expressions no longer supported for the Internet zone](http://msdn.microsoft.com/en-us/library/ie/dn384050(v=vs.85).aspx)
to learn more about them.

To resolve this error please specify the proper doctype at the top of your main html document:
Expand Down
12 changes: 6 additions & 6 deletions src/ng/sce.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function $SceDelegateProvider() {
*
* As of version 1.2, Angular ships with SCE enabled by default.
*
* Note: When enabled (the default), IE8 in quirks mode is not supported. In this mode, IE8 allows
* Note: When enabled (the default), IE<11 in quirks mode is not supported. In this mode, IE<11 allow
* one to execute arbitrary javascript by the use of the expression() syntax. Refer
* <http://blogs.msdn.com/b/ie/archive/2008/10/16/ending-expressions.aspx> to learn more about them.
* You can ensure your document is in standards mode and not quirks mode by adding `<!doctype html>`
Expand Down Expand Up @@ -727,13 +727,13 @@ function $SceProvider() {
* sce.js and sceSpecs.js would need to be aware of this detail.
*/

this.$get = ['$parse', '$sniffer', '$sceDelegate', function(
$parse, $sniffer, $sceDelegate) {
// Prereq: Ensure that we're not running in IE8 quirks mode. In that mode, IE allows
this.$get = ['$document', '$parse', '$sceDelegate', function(
$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 && $sniffer.msie && $sniffer.msieDocumentMode < 8) {
if (enabled && $document[0].documentMode < 8) {
throw $sceMinErr('iequirks',
'Strict Contextual Escaping does not support Internet Explorer version < 9 in quirks ' +
'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 ' +
'document. See http://docs.angularjs.org/api/ng.$sce for more information.');
}
Expand Down
5 changes: 1 addition & 4 deletions src/ng/sniffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function $SnifferProvider() {
int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
boxee = /Boxee/i.test(($window.navigator || {}).userAgent),
document = $document[0] || {},
documentMode = document.documentMode,
vendorPrefix,
vendorRegex = /^(Moz|webkit|O|ms)(?=[A-Z])/,
bodyStyle = document.body && document.body.style,
Expand Down Expand Up @@ -81,9 +80,7 @@ function $SnifferProvider() {
vendorPrefix: vendorPrefix,
transitions : transitions,
animations : animations,
android: android,
msie : msie,
msieDocumentMode: documentMode
android: android
};
}];
}
4 changes: 2 additions & 2 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('$location', function() {
var urlParsingNodePlaceholder;

beforeEach(inject(function ($sniffer) {
if ($sniffer.msie) return;
if (msie) return;

urlParsingNodePlaceholder = urlParsingNode;

Expand All @@ -38,7 +38,7 @@ describe('$location', function() {
}));

afterEach(inject(function ($sniffer) {
if ($sniffer.msie) return;
if (msie) return;
//reset urlParsingNode
urlParsingNode = urlParsingNodePlaceholder;
}));
Expand Down
11 changes: 5 additions & 6 deletions test/ng/sceSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ describe('SCE', function() {
}));
});

describe('IE8 quirks mode', function() {
describe('IE<11 quirks mode', function() {
function runTest(enabled, documentMode, expectException) {
module(function($provide) {
$provide.value('$sniffer', {
msie: documentMode,
msieDocumentMode: documentMode
});
$provide.value('$document', [{
documentMode: documentMode
}]);
$provide.value('$sceDelegate', {trustAs: null, valueOf: null, getTrusted: null});
});

Expand All @@ -47,7 +46,7 @@ describe('SCE', function() {
if (expectException) {
expect(constructSce).toThrowMinErr(
'$sce', 'iequirks', 'Strict Contextual Escaping does not support Internet Explorer ' +
'version < 9 in quirks mode. You can fix this by adding the text <!doctype html> to ' +
'version < 11 in quirks mode. You can fix this by adding the text <!doctype html> to ' +
'the top of your HTML document. See http://docs.angularjs.org/api/ng.$sce for more ' +
'information.');
} else {
Expand Down
12 changes: 0 additions & 12 deletions test/ng/snifferSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,4 @@ describe('$sniffer', function() {
expect($sniffer.android).toBe(2);
});
});

it('should return the internal msie flag', inject(function($sniffer) {
expect(isNaN($sniffer.msie)).toBe(isNaN(msie));
if (msie) {
expect($sniffer.msie).toBe(msie);
}
}));

it('should return document.documentMode as msieDocumentMode', function() {
var someDocumentMode = 123;
expect(sniffer({}, {documentMode: someDocumentMode}).msieDocumentMode).toBe(someDocumentMode);
});
});

0 comments on commit 64241a5

Please sign in to comment.