From 4473043623bc5bbab54f19f5095a2f899d28baf7 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 3 Oct 2022 09:20:54 +0200 Subject: [PATCH] Catch JSON.parse errors --- dev/Common/Html.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dev/Common/Html.js b/dev/Common/Html.js index 43888e266..dee7bab4b 100644 --- a/dev/Common/Html.js +++ b/dev/Common/Html.js @@ -21,11 +21,15 @@ const .replace(/tracking\.(printabout\.nl[^?]+)\?.*/gsi, (...m) => m[1]) .replace(/^.+awstrack\.me\/.+(https:%2F%2F[^/]+)/gsi, (...m) => decodeURIComponent(m[1])) .replace(/^.+\/track\/click\/.+\?p=([a-z0-9_]+)$/gsi, (...m) => { - let d = JSON.parse(atob(m[1].replace(/_/g,'/').replace(/-/g,'+'))); - if (d?.p) { - d = JSON.parse(d.p); + try { + let d = JSON.parse(atob(m[1].replace(/_/g,'/').replace(/-/g,'+'))); + if (d?.p) { + d = JSON.parse(d.p); + } + return d?.url || m[0]; + } catch (e) { + console.error(e); } - return d?.url || m[0]; }) .replace(/([?&])utm_[a-z]+=[^&?#]*/gsi, '$1') // Urchin Tracking Module .replace(/([?&])ec_[a-z]+=[^&?#]*/gsi, '$1') // Sitecore