Skip to content

jsonrpc calls do not escape single quotes properly, causes some jsonrpc calls to hang #4

@bradleypeabody

Description

@bradleypeabody

Using version 3.0.1. While using com.rabbitmq.client.RpcClient it appears there is a json encoding bug in com.rabbitmq.tools.json.JSONReader.

To reproduce, try an RPC call to a method like this:

 public String test123() { return "test'n"; }

Per our tests, the call hangs indefinitely. It traces down to the following:

In com.rabbitmq.tools.json.JSONReader - on line 90 it reads:

if (c == '"' || c == '\'') {

Per 42a7281 It looks like this was added as a fix so strings could be surrounded by single or double quotes. However, this incidentally makes it so unescaped single quotes inside a double quoted string are no longer handled properly.

The result is that the JSONReader goes into an infinite loop while trying to parse. On line 132:

while (token != OBJECT_END) {

This remains true, because it never gets a proper end, because the escaping is thrown off.

Possible solutions:

  • One simple change would be to modify com.rabbitmq.tools.json.JSONWriter so that it escapes single quotes with a backslash. This doesn't solve the fact that the json parsing is broken, but would at least work around this particular issue.
  • Fixing the json parsing code so it's actually (or at least more so) json compliant is of course more work but would handle more edge cases.

As an overall suggestion, I would recommend not writing your own json parsing code, and instead using something like http://code.google.com/p/json-smart/ It's simple to use, and would get rid of these kinds of edge case headaches on this. RabbitMQ already has it's own code base to worry about, not really much benefit to implementing json parsing like this. You might even be able to copy and paste out of it to bundle a minimal version, assuming the license is compatible (not sure on that).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions