Skip to content

Commit

Permalink
In getting IE version, prefer Trident version over MSIE version. (#1726)
Browse files Browse the repository at this point in the history
* In getting IE version, prefer Trident version over MSIE version.

* In getting IE version, revert preferring Trident version and check on documentMode instead.

* Added getieversion unit test.
  • Loading branch information
cfeltner committed Dec 10, 2021
1 parent 7f88c46 commit 8ad6d2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions shared/AppInsightsCommon/Tests/Unit/src/Util.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ export class UtilTests extends AITestClass {
}

Assert.equal(7, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"));
Assert.equal(7, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0;)"));
Assert.equal(7, Util.getIEVersion("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; en-US)"));
Assert.equal(7, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0;)"));
Assert.equal(8, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"));
Assert.equal(8, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"));
Assert.equal(8, Util.getIEVersion("Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"));
Expand All @@ -546,7 +546,16 @@ export class UtilTests extends AITestClass {
Assert.equal(11, Util.getIEVersion("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"));
Assert.equal(11, Util.getIEVersion("Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"));
Assert.equal(11, Util.getIEVersion("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko"));

const origDocMode = document['documentMode'];
document['documentMode'] = 11;

Assert.equal(11, Util.getIEVersion("Mozilla/4.0 (Compatible; MSIE 8.0; Windows NT 5.2; Trident/6.0)"));
Assert.equal(11, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Win64; x64; Trident/7.0; .NET4.0C; .NET4.0E)"));

// restore documentMode
document['documentMode'] = origDocMode;
}
});
}
}
}
5 changes: 4 additions & 1 deletion shared/AppInsightsCore/src/JavaScriptSDK/EnvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare var XDomainRequest: any;

const strWindow = "window";
const strDocument = "document";
const strDocumentMode = "documentMode";
const strNavigator = "navigator";
const strHistory = "history";
const strLocation = "location";
Expand Down Expand Up @@ -311,8 +312,10 @@ export function getIEVersion(userAgentStr: string = null): number {
}

var ua = (userAgentStr || "").toLowerCase();
// Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.
if (strContains(ua, strMsie)) {
return parseInt(ua.split(strMsie)[1]);
let doc = getDocument() || {} as Document;
return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
} else if (strContains(ua, strTrident)) {
let tridentVer = parseInt(ua.split(strTrident)[1]);
if (tridentVer) {
Expand Down

0 comments on commit 8ad6d2e

Please sign in to comment.