Redis query command doesn't accept spaced values (#12357)

* Handle string phrase with spaces value

* Unit test
This commit is contained in:
melohagan 2023-11-09 18:21:28 +00:00 committed by GitHub
parent bc5fa274a7
commit b68607b048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -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)

View File

@ -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"],
])
})
}) })