stipsan / ioredis-mock

Emulates ioredis by performing all operations in-memory.
MIT License
341 stars 125 forks source link

Bug in msetArgumentTransformer #1208

Open NeilASega opened 1 year ago

NeilASega commented 1 year ago

There's a bug in msetArgumentTransformer where it assumes that "typeof object" represents a JS object when arrays also return "object" as their type.

Following update fixes it:

const msetArgumentTransformer = function (args) {
    if (args.length === 1) {
        if (args[0] instanceof Map) {
            return (0, utils_1.convertMapToArray)(args[0]);
        }
        if (typeof args[0] === "object" && args[0] !== null) {
            if (Array.isArray(args[0])) {
                return args[0];
            }
            return (0, utils_1.convertObjectToArray)(args[0]);
        }
    }
    return args;
};

Thanks, Neil

NeilASega commented 1 year ago

Having investigated some more, I see that this function is in the "ioredis" module not "ioredis-mock" - so I've opened a new issue here: https://github.com/luin/ioredis/issues/1714

I will close this bug now and hope that "ioredis" devs fix it.

NeilASega commented 1 year ago

Unfortunately the problem has yet to be fixed by "ioredis". You can fix in "ioredis-mock" by adding...

args = args.flat();

...in "processArguments" function before calling the Command.transformer. This is essentially what "ioredis" is doing and hence why the bug does not present itself in their module.

dawsbot commented 1 year ago

@NeilASega if this is a widespread issue others might come across perhaps you could add a failing unit test to the codebase so that the discussion is easier to understand? I'm having trouble seeing the issue. It sounds like it also exists in redis itself?