Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
fix: a 3-byte UTF-8 character don't convert to hex string,ldap server…
Browse files Browse the repository at this point in the history
… can support \u or \U, but it is'n support hex string
  • Loading branch information
丁言河D0362319 committed Apr 22, 2024
1 parent 7aa09bc commit ba2e8c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/utils/escape-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/escape-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ba2e8c4

Please sign in to comment.