Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msetArgumentTransformer does not correctly handle arrays #1714

Open
NeilASega opened this issue Jan 29, 2023 · 1 comment
Open

msetArgumentTransformer does not correctly handle arrays #1714

NeilASega opened this issue Jan 29, 2023 · 1 comment

Comments

@NeilASega
Copy link

There appears to be a bug in the msetArgumentTransformer function:

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) {  <-- args[0] might be already be an array.
            return (0, utils_1.convertObjectToArray)(args[0]);
        }
    }
    return args;
};

The 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;
};

This problem came to light when using the MSETNX command via "ioredis-mock".

Thanks,
-Neil

@NeilASega
Copy link
Author

Can I get some traction on this please? Even though the issue only presents itself in "ioredis-mock", the bug is in "ioredis". The reason why "ioredis" works is because you call args.flat() in your Command.js constructor, otherwise it would fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant