Skip to content

Commit

Permalink
fix: fix payload encoding for v3 clients
Browse files Browse the repository at this point in the history
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
  • Loading branch information
darrachequesne committed Nov 6, 2021
1 parent 271e2df commit ed50fc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parser-v3/utf8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function utf8decode(byteString, opts) {
return ucs2encode(codePoints);
}

export default {
module.exports = {
version: '2.1.2',
encode: utf8encode,
decode: utf8decode
Expand Down
22 changes: 22 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const expect = require("expect.js");
const parser = require("../build/parser-v3/index.js");

describe("parser", () => {
it("properly encodes a mixed payload", done => {
parser.encodePayload(
[
{ type: "message", data: "€€€€" },
{ type: "message", data: Buffer.from([1, 2, 3]) }
],
true,
encoded => {
expect(encoded).to.be.a(Buffer);

parser.decodePayload(encoded, decoded => {
expect(decoded.data).to.eql("€€€€");
done();
});
}
);
});
});

0 comments on commit ed50fc3

Please # to comment.