From 688c255f9be4f5022f80b5a02d572b4be5dda090 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 25 Oct 2023 21:51:06 +0000 Subject: [PATCH] clean up getUrlQueryParam Remove dead getUrlQueryParam in SDK code, and also improve implementation in example project --- express_webpack/amp/index.html | 12 ++---------- express_webpack/index.html | 12 ++---------- src/shared/utils/utils.ts | 11 ----------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/express_webpack/amp/index.html b/express_webpack/amp/index.html index dbadd4072..c819ebaee 100644 --- a/express_webpack/amp/index.html +++ b/express_webpack/amp/index.html @@ -6,16 +6,8 @@ const SERVICE_WORKER_PATH = "push/onesignal/"; function getUrlQueryParam(name) { - var url = window.location.href; - // This is just to avoid case sensitiveness - url = url.toLowerCase(); - // This is just to avoid case sensitiveness for query parameter name - name = name.replace(/[\[\]]/g, "\\$&").toLowerCase(); - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), - results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, " ")); + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get(name); } const appId = getUrlQueryParam('app_id'); diff --git a/express_webpack/index.html b/express_webpack/index.html index 415bbfcaa..a85e97b58 100644 --- a/express_webpack/index.html +++ b/express_webpack/index.html @@ -17,16 +17,8 @@ let showEventAlertToggleSetting = false; function getUrlQueryParam(name) { - var url = window.location.href; - // This is just to avoid case sensitiveness - url = url.toLowerCase(); - // This is just to avoid case sensitiveness for query parameter name - name = name.replace(/[\[\]]/g, "\\$&").toLowerCase(); - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), - results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, " ")); + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get(name); } const appId = getUrlQueryParam('app_id'); diff --git a/src/shared/utils/utils.ts b/src/shared/utils/utils.ts index 9d28d7117..062813da3 100755 --- a/src/shared/utils/utils.ts +++ b/src/shared/utils/utils.ts @@ -273,17 +273,6 @@ export function isValidUuid(uuid: string) { return OneSignalUtils.isValidUuid(uuid); } -export function getUrlQueryParam(name: string) { - let url = window.location.href; - url = url.toLowerCase(); // This is just to avoid case sensitiveness - name = name.replace(/[[\]]/g, '\\$&').toLowerCase(); // This is just to avoid case sensitiveness for query parameter name - const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), - results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, ' ')); -} - /** * Wipe OneSignal-related IndexedDB data on the "correct" computed origin, but OneSignal must be initialized first to use. */