From 1330d256c4d0d30634be9066bf344ad5e91fd9e2 Mon Sep 17 00:00:00 2001 From: Ty Irvine <39813066+tyirvine@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:55:53 -0700 Subject: [PATCH 1/2] Fix for Safari being unable to parse exponents in JSON.parse() --- content_scripts/vimium.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content_scripts/vimium.css b/content_scripts/vimium.css index 44a189cc0..0c30bfaeb 100644 --- a/content_scripts/vimium.css +++ b/content_scripts/vimium.css @@ -4,7 +4,7 @@ * the style of our Vimium dialogs. * * The z-indexes of Vimium elements are very large, because we always want them to show on top. We - * know that Chrome supports z-index values up to about 2^31. The values we use are large numbers + * know that Chrome supports z-index values up to about 2,147,483,648. The values we use are large numbers * approaching that bound. However, we must leave headroom for link hints. Hint marker z-indexes * start at 2140000001. */ @@ -33,7 +33,7 @@ tr.vimiumReset { cursor: auto; display: inline; float: none; - font-family : "Helvetica Neue", "Helvetica", "Arial", sans-serif; + font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif; font-size: inherit; font-style: normal; font-variant: normal; From 0ba9bd131589b93f3cc80df9833ad2ab6c1112ed Mon Sep 17 00:00:00 2001 From: Ty Irvine <39813066+tyirvine@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:08:13 -0700 Subject: [PATCH 2/2] Validate value is a stringified JSON object before parsing --- lib/settings.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/settings.js b/lib/settings.js index 1df454512..990c6426f 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -156,12 +156,23 @@ const Settings = { const shouldMigrate = settings["settingsVersion"] == null; if (!shouldMigrate) return settings; + // Safari struggles to parse anything that isn't a stringified JSON object when using JSON.parse(). + // This ensures that only stringified JSON objects get passed into the parser. + const isValidJSON = (str) => { + try { + JSON.parse(str); + return true; + } catch (e) { + return false; + } + }; + // Migration for v2.0.0: decode all values so that they're not JSON string encoded. const newSettings = {}; for (const [k, v] of Object.entries(settings)) { // Most pre-2.0 settings were strings, but the global marks were stored as native values. See // #4323. So check the setting value's type before migrating. - if (typeof v === "string") { + if (typeof v === "string" && isValidJSON(v)) { newSettings[k] = JSON.parse(v); } else { newSettings[k] = v;