bbyars / mountebank

Over the wire test doubles
http://www.mbtest.org
MIT License
2k stars 262 forks source link

bug in src/util/helpers.js merge function for case with an Array field #750

Open tbarabanov opened 8 months ago

tbarabanov commented 8 months ago

my custom imposter config

{
   "port":"8029",
   "protocol":"custom",
   "name":"pike",
   "array": ["a", "b"]
}

mb code

function merge (defaults, overrides) {
    const result = clone(defaults);
    Object.keys(overrides).forEach(key => {
        if (typeof overrides[key] === 'object' && overrides[key] !== null) {
            result[key] = merge(result[key] || {}, overrides[key]);
        }
        else {
            result[key] = overrides[key];
        }
    });
    return result;
}

since typeof Array is object imposter will get wrong args:

{
   "port":"8029",
   "callbackURLTemplate":"http://localhost:8025/imposters/:port/_requests",
   "loglevel":"debug",
   "allowInjection":true,
   ...
   "array":{"0":"a", "1":"b"}
}

Expected behaviour

mb must leave arrays as is

Actual behaviour

mb breaks the config

mb version 2.7.0