From ae5dc6299e513cb75c601fcebadff3a7235de6a4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 29 Aug 2024 13:47:48 -0400 Subject: [PATCH] Improve `validate-constant` scriptlet helper Add support for `json:`-prefixed values. --- assets/resources/scriptlets.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index f450b88a9b903..a3196208d1f5e 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -531,7 +531,9 @@ function validateConstantFn(trusted, raw, extraArgs = {}) { if ( isNaN(raw) ) { return; } if ( Math.abs(raw) > 0x7FFF ) { return; } } else if ( trusted ) { - if ( raw.startsWith('{') && raw.endsWith('}') ) { + if ( raw.startsWith('json:') ) { + try { value = safe.JSON_parse(raw.slice(5)); } catch(ex) { return; } + } else if ( raw.startsWith('{') && raw.endsWith('}') ) { try { value = safe.JSON_parse(raw).value; } catch(ex) { return; } } } else {