From 04135b14b50fd24398d6bf58ec42132e084ee280 Mon Sep 17 00:00:00 2001 From: Kai Mallea Date: Sat, 10 Aug 2019 23:11:41 -0400 Subject: [PATCH] feat: update amazon regexp for better matching supersedes #88 --- src/__tests__/amazon.test.ts | 36 ++++++++++++++++++++++++++++++++++++ src/isMobile.ts | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/__tests__/amazon.test.ts b/src/__tests__/amazon.test.ts index 69bd10d..ec45d8b 100644 --- a/src/__tests__/amazon.test.ts +++ b/src/__tests__/amazon.test.ts @@ -507,4 +507,40 @@ describe('Amazon', () => { expect(mobile.android.device).toBe(true); }); }); + + describe('Amazon Fire Generic Phone User Agent', () => { + beforeEach(() => { + userAgent = + 'Mozilla/5.0 (Linux; Android android-version; product-model Build/product-build) AppleWebKit/webkit-version (KHTML, like Gecko) Silk/browser-version like Chrome/chrome-version Mobile Safari/webkit-version'; + mobile = isMobile(userAgent); + }); + + test('should be an Amazon Phone', () => { + expect(mobile.amazon.phone).toBe(true); + }); + + test('should not be an Amazon Tablet', () => { + expect(mobile.amazon.tablet).not.toBe(true); + }); + + test('should be an Amazon device', () => { + expect(mobile.amazon.device).toBe(true); + }); + + test('should be an Android Phone', () => { + expect(mobile.android.phone).toBe(true); + }); + + test('should not be an Android Tablet', () => { + expect(mobile.android.tablet).not.toBe(true); + }); + + test('should be matched as Any Phone', () => { + expect(mobile.phone).toBe(true); + }); + + test('should be an Android device', () => { + expect(mobile.android.device).toBe(true); + }); + }); }); diff --git a/src/isMobile.ts b/src/isMobile.ts index 72c045c..2269f3f 100644 --- a/src/isMobile.ts +++ b/src/isMobile.ts @@ -3,8 +3,8 @@ const appleIpod = /iPod/i; const appleTablet = /iPad/i; const androidPhone = /\bAndroid(?:.+)Mobile\b/i; // Match 'Android' AND 'Mobile' const androidTablet = /Android/i; -const amazonPhone = /\bAndroid(?:.+)SD4930UR\b/i; -const amazonTablet = /\bAndroid(?:.+)(?:KF[A-Z]{2,4})\b/i; +const amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i; // Match 'Silk' AND 'Mobile' +const amazonTablet = /Silk/i; const windowsPhone = /Windows Phone/i; const windowsTablet = /\bWindows(?:.+)ARM\b/i; // Match 'Windows' AND 'ARM' const otherBlackBerry = /BlackBerry/i;