Redis query command doesn't accept spaced values (#12357)
* Handle string phrase with spaces value * Unit test
This commit is contained in:
parent
bc5fa274a7
commit
b68607b048
|
@ -165,10 +165,22 @@ class RedisIntegration {
|
||||||
// commands split line by line
|
// commands split line by line
|
||||||
const commands = query.json.trim().split("\n")
|
const commands = query.json.trim().split("\n")
|
||||||
let pipelineCommands = []
|
let pipelineCommands = []
|
||||||
|
let tokenised
|
||||||
|
|
||||||
// process each command separately
|
// process each command separately
|
||||||
for (let command of commands) {
|
for (let command of commands) {
|
||||||
const tokenised = command.trim().split(" ")
|
const valueToken = command.trim().match(/".*"/)
|
||||||
|
if (valueToken?.[0]) {
|
||||||
|
tokenised = [
|
||||||
|
...command
|
||||||
|
.substring(0, command.indexOf(valueToken[0]) - 1)
|
||||||
|
.trim()
|
||||||
|
.split(" "),
|
||||||
|
valueToken?.[0],
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
tokenised = command.trim().split(" ")
|
||||||
|
}
|
||||||
// Pipeline only accepts lower case commands
|
// Pipeline only accepts lower case commands
|
||||||
tokenised[0] = tokenised[0].toLowerCase()
|
tokenised[0] = tokenised[0].toLowerCase()
|
||||||
pipelineCommands.push(tokenised)
|
pipelineCommands.push(tokenised)
|
||||||
|
|
|
@ -85,4 +85,21 @@ describe("Redis Integration", () => {
|
||||||
["get", "foo"],
|
["get", "foo"],
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("calls the pipeline method with double quoted phrase values", async () => {
|
||||||
|
const body = {
|
||||||
|
json: 'SET foo "What a wonderful world!"\nGET foo',
|
||||||
|
}
|
||||||
|
|
||||||
|
// ioredis-mock doesn't support pipelines
|
||||||
|
config.integration.client.pipeline = jest.fn(() => ({
|
||||||
|
exec: jest.fn(() => [[]]),
|
||||||
|
}))
|
||||||
|
|
||||||
|
await config.integration.command(body)
|
||||||
|
expect(config.integration.client.pipeline).toHaveBeenCalledWith([
|
||||||
|
["set", "foo", '"What a wonderful world!"'],
|
||||||
|
["get", "foo"],
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue