mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Assume bad JSON is string in set-prop
Assume value is supposed to be a string if it fails to parse as JSON and
it does not start and end in a [], {}, or "" pair.
This commit is contained in:
1 parent
1b901f5d1c
commit
201eb89dcd
1 file changed
+22
-1
+22
-1
@@ -158,11 +158,32 @@ instanceConfigCommands.add(new libCommand.Command({
|
|||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
|
let value = args.value;
|
||||||
|
try {
|
||||||
|
value = JSON.parse(value);
|
||||||
|
} catch (err) {
|
||||||
|
// If this is looks like an array, object or string literal
|
||||||
|
// throw the parse error, otherwise assume this is a string.
|
||||||
|
// The resoning behind this is that correctly quoting the string
|
||||||
|
// with the all the layers of quote removal at play is difficult.
|
||||||
|
// See the following table for how to pass "That's a \" quote" in
|
||||||
|
// different environments:
|
||||||
|
// cmd : """""That's a \\"" quote"""""
|
||||||
|
// cmd + npx : """""""""""That's a \\\\"""" quote"""""""""""
|
||||||
|
// PowerShell : '"""""That''s a \\"" quote"""""'
|
||||||
|
// PowerShell + npx : '"""""""""""That''s a \\\\"""" quote"""""""""""'
|
||||||
|
// bash : '""That'\''s a \" quote""'
|
||||||
|
// bash + npx : '""That'\''s a \" quote""'
|
||||||
|
// bash + npx -s sh : "'\"\"That'\\''s a \\\" quote\"\"'"
|
||||||
|
if (/^(\[.*]|{.*}|".*")$/.test(value)) {
|
||||||
|
throw new libErrors.CommandError(`In parsing value '${value}': ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
await libLink.messages.setInstanceConfigProp.send(control, {
|
await libLink.messages.setInstanceConfigProp.send(control, {
|
||||||
instance_id: instanceId,
|
instance_id: instanceId,
|
||||||
field: args.field,
|
field: args.field,
|
||||||
prop: args.prop,
|
prop: args.prop,
|
||||||
value: JSON.parse(args.value),
|
value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in new issue
Block a user