Skip to content

Commit

Permalink
fix: Handle an odd case with the user agent (#242)
Browse files Browse the repository at this point in the history
* Handle an odd case with the user agent

* test isMsie

* make isMsie testable and test it
  • Loading branch information
aub authored and Haroenv committed Aug 3, 2018
1 parent 55807b8 commit c194736
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/common/utils.js
Expand Up @@ -18,10 +18,14 @@ module.exports = {
map: null,
mixin: null,

isMsie: function() {
isMsie: function(agentString) {
if (agentString === undefined) { agentString = navigator.userAgent; }
// from https://github.com/ded/bowser/blob/master/bowser.js
return (/(msie|trident)/i).test(navigator.userAgent) ?
navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false;
if ((/(msie|trident)/i).test(agentString)) {
var match = agentString.match(/(msie |rv:)(\d+(.\d+)?)/i);
if (match) { return match[2]; }
}
return false;
},

// http://stackoverflow.com/a/6969486
Expand Down
23 changes: 23 additions & 0 deletions test/unit/utils_spec.js
Expand Up @@ -18,4 +18,27 @@ describe('escapeHTML', function() {
var actual = _.escapeHighlightedString(test, '<span class="highlighted">', '</span>');
expect(actual).toEqual('<span class="highlighted">&lt;img src=VALUE1 onerror=alert(1) /&gt;</span>OTHER CONTENT<span class="highlighted">VALUE2</span>OTHER CONTENT$');
});

it('should report the isMsie state correctly', function() {
var actual = _.isMsie();
expect(actual).toEqual(false);
});

it('should report the isMsie state correctly under a non-IE browser', function() {
var ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36';
var actual = _.isMsie(ua);
expect(actual).toEqual(false);
});

it('should report the isMsie state correctly under an IE browser', function() {
var ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko';
var actual = _.isMsie(ua);
expect(actual).toEqual('11.0');
});

it('should report the isMsie state correctly under a browser that includes Trident but is not IE', function() {
var ua = 'Mozilla/5.0 (iPad; CPU OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 KurogoVersion/2.7.7 (Kurogo iOS Tablet) KurogoOSVersion/11.4.1 KurogoAppVersion/2.0.1 (com.telerik.TridentUniversity)';
var actual = _.isMsie(ua);
expect(actual).toEqual(false);
});
});

0 comments on commit c194736

Please sign in to comment.