Skip to content

Commit ed50fc3

Browse files
fix: fix payload encoding for v3 clients
The v3 parser (used for compatibility with older clients) was broken during the migration to TypeScript ([1]). This was not caught in the test suite because the Node.js client does not support binary packet in polling mode (packets are base64-encoded). [1]: c0d6eaa Backported from 6.0.x branch: 3f42262
1 parent 271e2df commit ed50fc3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/parser-v3/utf8.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function utf8decode(byteString, opts) {
203203
return ucs2encode(codePoints);
204204
}
205205

206-
export default {
206+
module.exports = {
207207
version: '2.1.2',
208208
encode: utf8encode,
209209
decode: utf8decode

test/parser.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const expect = require("expect.js");
2+
const parser = require("../build/parser-v3/index.js");
3+
4+
describe("parser", () => {
5+
it("properly encodes a mixed payload", done => {
6+
parser.encodePayload(
7+
[
8+
{ type: "message", data: "€€€€" },
9+
{ type: "message", data: Buffer.from([1, 2, 3]) }
10+
],
11+
true,
12+
encoded => {
13+
expect(encoded).to.be.a(Buffer);
14+
15+
parser.decodePayload(encoded, decoded => {
16+
expect(decoded.data).to.eql("€€€€");
17+
done();
18+
});
19+
}
20+
);
21+
});
22+
});

0 commit comments

Comments
 (0)