allow to enter strings with quote marks in raw tag editor's text mode (#10371)

and use fully quoted strings for cases which have characters that need to be encoded

old: tag=foo\"bar\" -> new: tag=foo"bar" or tag="foo\"bar\""
old: tag=foo\nbar   -> new: tag="foo\nbar"

falls back to raw tag values if a quoted string cannot be parsed
This commit is contained in:
Martin Raifer
2024-08-01 15:19:33 +02:00
committed by GitHub
parent 8ea6511ed2
commit 945fea1dc0
+15 -11
View File
@@ -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) {