diff --git a/modules/ui/sections/raw_tag_editor.js b/modules/ui/sections/raw_tag_editor.js index 2db9c4d2e..672dff86a 100644 --- a/modules/ui/sections/raw_tag_editor.js +++ b/modules/ui/sections/raw_tag_editor.js @@ -321,21 +321,25 @@ export function uiSectionRawTagEditor(id, context) { } function stringify(s) { - return JSON.stringify(s).slice(1, -1); // without leading/trailing " + const stringified = JSON.stringify(s).slice(1, -1); // without leading/trailing " + if (stringified !== s) { + return `"${stringified}"`; + } else { + return s; + } } function unstringify(s) { - var leading = ''; - var trailing = ''; - if (s.length < 1 || s.charAt(0) !== '"') { - leading = '"'; + const isQuoted = s.length > 1 && s.charAt(0) === '"' && s.charAt(s.length - 1) === '"'; + if (isQuoted) { + try { + return JSON.parse(s); + } catch { + return s; + } + } else { + return s; } - if (s.length < 2 || s.charAt(s.length - 1) !== '"' || - (s.charAt(s.length - 1) === '"' && s.charAt(s.length - 2) === '\\') - ) { - trailing = '"'; - } - return JSON.parse(leading + s + trailing); } function rowsToText(rows) {