Catch JSON.parse errors

This commit is contained in:
the-djmaze 2022-10-03 09:20:54 +02:00
parent 8980fc9cb1
commit 4473043623

View file

@ -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