Skip to content

Commit

Permalink
Improve validate-constant scriptlet helper
Browse files Browse the repository at this point in the history
Add support for `json:`-prefixed values.
  • Loading branch information
gorhill committed Aug 29, 2024
1 parent b1f28b4 commit ae5dc62
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ae5dc62

Please sign in to comment.