Skip to content

Commit 9ddb58b

Browse files
authored
fix: handle non-utf8 command name (#866)
This commit uses Buffer.byteLength() insteand of String#length to handle non-utf8 command names. Close #862
1 parent 519d481 commit 9ddb58b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/command.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export default class Command {
220220
}
221221

222222
let result
223-
let commandStr = '*' + (this.args.length + 1) + '\r\n$' + this.name.length + '\r\n' + this.name + '\r\n'
223+
let commandStr = '*' + (this.args.length + 1) + '\r\n$' + Buffer.byteLength(this.name) + '\r\n' + this.name + '\r\n'
224224
if (bufferMode) {
225225
const buffers = new MixedBuffers();
226226
buffers.push(commandStr);

test/functional/send_command.js

+13
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,17 @@ describe('send command', function () {
207207
});
208208
});
209209
});
210+
211+
it('throws for invalid command', async () => {
212+
const redis = new Redis()
213+
const invalidCommand = 'áéűáű'
214+
let err
215+
try {
216+
await redis.call(invalidCommand, [])
217+
} catch(e) {
218+
err = e.message
219+
}
220+
expect(err).to.contain('unknown command')
221+
expect(err).to.contain(invalidCommand)
222+
})
210223
});

0 commit comments

Comments
 (0)