From ba2e8c4a7231acb0fbaf0b0fc8dc80c7d7395eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E8=A8=80=E6=B2=B3D0362319?= Date: Thu, 18 Apr 2024 17:23:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20a=203-byte=20UTF-8=20character=20don't?= =?UTF-8?q?=20convert=20to=20hex=20string=EF=BC=8Cldap=20server=20can=20su?= =?UTF-8?q?pport=20\u=20or=20\U,=20but=20it=20is'n=20support=20hex=20strin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/escape-value.js | 4 +--- lib/utils/escape-value.test.js | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/utils/escape-value.js b/lib/utils/escape-value.js index d9ccf98..ebc6afd 100644 --- a/lib/utils/escape-value.js +++ b/lib/utils/escape-value.js @@ -58,9 +58,7 @@ module.exports = function escapeValue (value) { if (charHex >= 0xe0 && charHex <= 0xef) { // Represents the first byte in a 3-byte UTF-8 character. - escaped.push(toEscapedHexString(charHex)) - escaped.push(toEscapedHexString(toEscape[i + 1])) - escaped.push(toEscapedHexString(toEscape[i + 2])) + escaped.push(Buffer.from([charHex, toEscape[i + 1], toEscape[i + 2]], 'utf8').toString()) i += 3 continue } diff --git a/lib/utils/escape-value.test.js b/lib/utils/escape-value.test.js index 9f7ba71..1191f97 100644 --- a/lib/utils/escape-value.test.js +++ b/lib/utils/escape-value.test.js @@ -47,7 +47,11 @@ tap.test('2-byte utf-8', t => { tap.test('3-byte utf-8', t => { t.test('₠', async t => { - t.equal(escapeValue('₠'), '\\e2\\82\\a0') + t.equal(escapeValue('₠'), '₠') + }) + + t.test('中文', async t => { + t.equal(escapeValue('中文'), '中文') }) t.end()