Skip to content

Commit

Permalink
[fix] the reply subject buffer was copied from the offset of the repl…
Browse files Browse the repository at this point in the history
…y rather than the subject, providing the client with an incorrect reply subject. (#134)

FIX #134
  • Loading branch information
aricart committed Mar 27, 2021
1 parent 5a85362 commit 7907036
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ src/version.json
old_tests/
examples/certs/


debug/
.idea/

# nyc test coverage
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export class Parser {
this.argBuf = new DenoBuffer(buf);
this.ma.subject = buf.subarray(0, s);
if (this.ma.reply) {
this.ma.reply = buf.subarray(r);
this.ma.reply = buf.subarray(s);
}
}

Expand Down
23 changes: 23 additions & 0 deletions tests/parser_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,29 @@ Deno.test("parser - header", () => {
assertEquals(td.decode(payload!.subarray(d.msgs[0].msg?.hdr)), "bar");
});

Deno.test("parser - subject", () => {
const d = new TestDispatcher();
const p = new Parser(d);
p.parse(
te.encode(
`MSG foo 1 _INBOX.4E66Z7UREYUY9VKDNFBT1A.4E66Z7UREYUY9VKDNFBT72.4E66Z7UREYUY9VKDNFBSVI 102400\r\n`,
),
);
for (let i = 0; i < 100; i++) {
p.parse(new Uint8Array(1024));
}
assertEquals(p.ma.size, 102400, `size ${p.ma.size}`);
assertEquals(p.ma.sid, 1, "sid");
assertEquals(p.ma.subject, te.encode("foo"), "subject");
assertEquals(
p.ma.reply,
te.encode(
"_INBOX.4E66Z7UREYUY9VKDNFBT1A.4E66Z7UREYUY9VKDNFBT72.4E66Z7UREYUY9VKDNFBSVI",
),
"reply",
);
});

Deno.test("parser - msg buffers don't clobber", () => {
parserClobberTest(false);
});
Expand Down

0 comments on commit 7907036

Please sign in to comment.