Skip to content

Commit

Permalink
Merge pull request #2531 from kuzzleio/fix/hset-and-hmset-0-value
Browse files Browse the repository at this point in the history
fix: hmset, mset should accept value = 0
  • Loading branch information
Juiced66 committed May 22, 2024
2 parents 6e3dda6 + cb685f9 commit 8099cc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/api/controllers/memoryStorageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,15 @@ function initMapping() {
kassert.assertBodyAttributeType(request, "entries", "array");

val.forEach((v) => {
if (typeof v !== "object" || !v.field || !v.value) {
if (
typeof v !== "object" ||
!v.field ||
(!v.value && v.value !== 0)
) {
throw kerror.get(
"invalid_argument",
"entries",
"<array of object>",
"<array of objects>",
);
}

Expand Down Expand Up @@ -348,7 +352,11 @@ function initMapping() {
kassert.assertBodyHasAttribute(request, "entries");
kassert.assertBodyAttributeType(request, "entries", "array");
val.forEach((entry) => {
if (typeof entry !== "object" || !entry.key || !entry.value) {
if (
typeof entry !== "object" ||
!entry.key ||
(!entry.value && entry.value !== 0)
) {
throw kerror.get(
"invalid_argument",
"entries",
Expand Down
4 changes: 4 additions & 0 deletions test/api/controllers/memoryStorageController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ describe("MemoryStorageController", () => {
entries: [
{ field: "foo", value: "bar" },
{ field: "baz", value: "qux" },
{ field: "bar", value: 0 },
],
},
});
Expand Down Expand Up @@ -1096,6 +1097,7 @@ describe("MemoryStorageController", () => {
{ key: "key1", value: "value1" },
{ key: "key2", value: "value2" },
{ key: "key3", value: "value3" },
{ key: "key4", value: 0 },
],
},
});
Expand All @@ -1109,6 +1111,8 @@ describe("MemoryStorageController", () => {
"value2",
"key3",
"value3",
"key4",
0,
]);
});

Expand Down

0 comments on commit 8099cc2

Please sign in to comment.