Skip to content

Commit

Permalink
fix: handle non-utf8 command name (#866)
Browse files Browse the repository at this point in the history
This commit uses Buffer.byteLength() insteand of
String#length to handle non-utf8 command names.

Close #862
  • Loading branch information
luin authored May 13, 2019
1 parent 519d481 commit 9ddb58b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default class Command {
}

let result
let commandStr = '*' + (this.args.length + 1) + '\r\n$' + this.name.length + '\r\n' + this.name + '\r\n'
let commandStr = '*' + (this.args.length + 1) + '\r\n$' + Buffer.byteLength(this.name) + '\r\n' + this.name + '\r\n'
if (bufferMode) {
const buffers = new MixedBuffers();
buffers.push(commandStr);
Expand Down
13 changes: 13 additions & 0 deletions test/functional/send_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,17 @@ describe('send command', function () {
});
});
});

it('throws for invalid command', async () => {
const redis = new Redis()
const invalidCommand = 'áéűáű'
let err
try {
await redis.call(invalidCommand, [])
} catch(e) {
err = e.message
}
expect(err).to.contain('unknown command')
expect(err).to.contain(invalidCommand)
})
});

0 comments on commit 9ddb58b

Please sign in to comment.