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

Some objectGUID buffer cause error in escape filter function #10

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/utils/escape-filter-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ function escapeFilterValue (toEscape) {
}

function escapeBuffer (buf) {
let result = ''
let bufLen = buf.length;
ciePIC marked this conversation as resolved.
Show resolved Hide resolved
let result = '';
for (let i = 0; i < buf.length; i += 1) {
if (buf[i] >= 0xc0 && buf[i] <= 0xdf) {
// Represents the first byte in a 2-byte UTF-8 character.
result += '\\' + buf[i].toString(16) + '\\' + buf[i + 1].toString(16)
result += '\\' + buf[i].toString(16);
if(i<bufLen-1) { result += '\\' + buf[i + 1].toString(16); } //Only add second byte if exist in buffer
jsumners marked this conversation as resolved.
Show resolved Hide resolved
i += 1
continue
}

if (buf[i] >= 0xe0 && buf[i] <= 0xef) {
// Represents the first byte in a 3-byte UTF-8 character.
result += [
'\\', buf[i].toString(16),
'\\', buf[i + 1].toString(16),
'\\', buf[i + 2].toString(16)
].join('')
result += '\\' + buf[i].toString(16);
if(i<bufLen-1) { result += '\\' + buf[i + 1].toString(16); } //Only add second byte if exist in buffer
if(i<bufLen-2) { result += '\\' + buf[i + 2].toString(16); } //Only add third byte if exist in buffer
i += 2
continue
}
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/escape-filter-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ tap.test('leaves encoded characters intact', async t => {
t.equal(result, expected[i])
}
})

tap.test('parse binary data with end byte >0xc0', async t => {
const input = Buffer.from([0x30, 0x41, 0x62, 0xd2])
const expected = '0Ab\\d2'
t.equal(escapeFilterValue(input), expected)
})
ciePIC marked this conversation as resolved.
Show resolved Hide resolved