Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Ensures that Firefox iOS is excluded from UA checks for Firefox (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckharmston authored and Donovan Preston committed Jan 18, 2018
1 parent 80698be commit 7b7c15f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion frontend/src/app/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export function buildSurveyURL(ref, title, installed, clientUUID, survey_url) {
}

export function isFirefox(ua) {
return ua.indexOf("firefox") > -1 || ua.indexOf("fxios") > -1;
const userAgent = ua.toLowerCase();
return userAgent.indexOf("firefox") > -1 && userAgent.indexOf("fxios") === -1;
}

export function isMinFirefoxVersion(ua, minVersion) {
Expand Down
31 changes: 30 additions & 1 deletion frontend/test/app/lib/utils-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { l10nIdFormat, l10nId, experimentL10nId, newsUpdateL10nId, lookup } from "../../../src/app/lib/utils";
import { isFirefox, l10nIdFormat, l10nId, experimentL10nId, newsUpdateL10nId, lookup } from "../../../src/app/lib/utils";

describe("app/lib/utils", () => {

Expand Down Expand Up @@ -125,4 +125,33 @@ describe("app/lib/utils", () => {

});

describe("isFirefox", () => {

it("should recognize Firefox 58's UA string as Firefox", () => {
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0';
expect(isFirefox(UA)).to.equal(true);
});

it("should not recognize Chrome's UA string as Firefox", () => {
const UA = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36';
expect(isFirefox(UA)).to.equal(false);
});

it("should not recognize Firefox for iOS/iPod's UA string as Firefox", () => {
const UA = 'Mozilla/5.0 (iPod touch; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4';
expect(isFirefox(UA)).to.equal(false);
});

it("should not recognize Firefox for iOS/iPhone's UA string as Firefox", () => {
const UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4';
expect(isFirefox(UA)).to.equal(false);
});

it("should not recognize Firefox for iOS/iPad's UA string as Firefox", () => {
const UA = 'Mozilla/5.0 (iPad; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4';
expect(isFirefox(UA)).to.equal(false);
});

});

});

0 comments on commit 7b7c15f

Please sign in to comment.