You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-12-08 09:22:13 +03:00
fix: multi-byte character corruption when converting Buffers to strings (#3100)
* add tests for multi-byte character buffer * support multi-byte characters when decoding buffers fixes: #2993
This commit is contained in:
@@ -226,6 +226,11 @@ describe('RESP Decoder', () => {
|
||||
toWrite: Buffer.from('+OK\r\n'),
|
||||
replies: [Buffer.from('OK')]
|
||||
});
|
||||
|
||||
test("'é'", {
|
||||
toWrite: Buffer.from('+é\r\n'),
|
||||
replies: ['é']
|
||||
});
|
||||
});
|
||||
|
||||
describe('BlobString', () => {
|
||||
@@ -251,6 +256,11 @@ describe('RESP Decoder', () => {
|
||||
toWrite: Buffer.from('$2\r\nOK\r\n'),
|
||||
replies: [Buffer.from('OK')]
|
||||
});
|
||||
|
||||
test("'é'", {
|
||||
toWrite: Buffer.from('$2\r\né\r\n'),
|
||||
replies: ['é']
|
||||
});
|
||||
});
|
||||
|
||||
describe('VerbatimString', () => {
|
||||
@@ -279,6 +289,11 @@ describe('RESP Decoder', () => {
|
||||
toWrite: Buffer.from('=6\r\ntxt:OK\r\n'),
|
||||
replies: [Buffer.from('OK')]
|
||||
});
|
||||
|
||||
test("'é'", {
|
||||
toWrite: Buffer.from('=6\r\ntxt:é\r\n'),
|
||||
replies: ['é']
|
||||
});
|
||||
});
|
||||
|
||||
test('SimpleError', {
|
||||
|
||||
@@ -506,9 +506,8 @@ export class Decoder {
|
||||
}
|
||||
|
||||
chunks.push(chunk.subarray(start, crlfIndex));
|
||||
return type === Buffer ?
|
||||
Buffer.concat(chunks) :
|
||||
chunks.join('');
|
||||
const buffer = Buffer.concat(chunks);
|
||||
return type === Buffer ? buffer : buffer.toString();
|
||||
}
|
||||
|
||||
#decodeBlobString(type, chunk) {
|
||||
@@ -578,9 +577,8 @@ export class Decoder {
|
||||
|
||||
chunks.push(chunk.subarray(this.#cursor, end));
|
||||
this.#cursor = end + skip;
|
||||
return type === Buffer ?
|
||||
Buffer.concat(chunks) :
|
||||
chunks.join('');
|
||||
const buffer = Buffer.concat(chunks);
|
||||
return type === Buffer ? buffer : buffer.toString();
|
||||
}
|
||||
|
||||
#decodeBlobStringWithLength(length, type, chunk) {
|
||||
|
||||
Reference in New Issue
Block a user