mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user