MXS-2998: Fix key-value parsing

The code assumed that no value would hold an equals sign which is
wrong. Added a test case that reproduces the problem and verifies the fix.
This commit is contained in:
Markus Mäkelä
2020-05-14 08:02:43 +03:00
parent 481f6f1aea
commit 7c011b4081
2 changed files with 23 additions and 12 deletions

View File

@ -12,23 +12,27 @@
*/
require('./common.js')()
// Converts an array of key=value pairs into an object
// Converts a key=value string into an object
function to_obj(obj, value) {
var kv = value.split('=')
obj[kv[0]] = kv[1]
return obj
var pos = value.indexOf("=");
obj[value.slice(0, pos)] = value.slice(pos + 1);
return obj;
}
function validateParams(argv, params) {
var rval = null;
params.forEach((value) => {
var kv = value.split('=')
if (!kv || kv.length != 2) {
rval = 'Not a key-value parameter: ' + value
}
})
var rval = null;
params.forEach((value) => {
try {
var pos = value.indexOf("=");
if (pos == -1) {
rval = "Not a key-value parameter: " + value;
}
} catch (err) {
rval = "Not a key-value parameter: " + value;
}
});
return rval
return rval;
}
exports.command = 'create <command>'