From e6ce478838f37591b2eae62e8faf76c28e1b12ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20B=C3=A4r?= Date: Mon, 6 Jan 2025 14:34:52 +0100 Subject: [PATCH] fix: better Safari `user-agent` parsing, fix tests --- .../src/generator-networks-creator.ts | 8 ++++---- .../generator-networks-creator.test.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/generator-networks-creator/src/generator-networks-creator.ts b/packages/generator-networks-creator/src/generator-networks-creator.ts index 8b3b70cf..b245cd5b 100755 --- a/packages/generator-networks-creator/src/generator-networks-creator.ts +++ b/packages/generator-networks-creator/src/generator-networks-creator.ts @@ -133,10 +133,10 @@ export class GeneratorNetworksCreator { edgios: 'edge', } as Record; - const unsupportedBrowsers = /opr|yabrowser|SamsungBrowser|UCBrowser|vivaldi/ig; - const edge = /(edg(a|ios|e)?)\/([0-9.]*)/ig; - const safari = /Version\/([\d.]+) Safari/i; - const supportedBrowsers = /(firefox|fxios|chrome|crios)\/([0-9.]*)/ig; + const unsupportedBrowsers = /opr|yabrowser|SamsungBrowser|UCBrowser|vivaldi/i; + const edge = /(edg(a|ios|e)?)\/([0-9.]*)/i; + const safari = /Version\/([\d.]+)( Mobile\/[a-z0-9]+)? Safari/i; + const supportedBrowsers = /(firefox|fxios|chrome|crios|safari)\/([0-9.]*)/i; if (unsupportedBrowsers.test(userAgent)) { return missingValueDatasetToken; diff --git a/test/generator-networks-creator/generator-networks-creator.test.ts b/test/generator-networks-creator/generator-networks-creator.test.ts index 7795f508..72923dcb 100644 --- a/test/generator-networks-creator/generator-networks-creator.test.ts +++ b/test/generator-networks-creator/generator-networks-creator.test.ts @@ -86,19 +86,19 @@ describe('Processing browser data', () => { }, { userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1", - expectedBrowser: "safari/604.1", + expectedBrowser: "safari/16.5", expectedOS: "ios", expectedDeviceType: "mobile" }, { userAgent: "Mozilla/5.0 (iPad; CPU OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1", - expectedBrowser: "safari/604.1", + expectedBrowser: "safari/16.5", expectedOS: "ios", expectedDeviceType: "mobile" }, { userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15", - expectedBrowser: "safari/605.1.15", + expectedBrowser: "safari/16.5", expectedOS: "macos", expectedDeviceType: "desktop" },