natemurthy / protobuf-java-format

Automatically exported from code.google.com/p/protobuf-java-format
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Incorrect Escaping of single quotes in string fields via JsonFormat.printToString() #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Define any message with a string field, e.g.
message TestMessage {
    required string test_string = 1;
}
2. Create an instance of this message with a string containing a single quote, 
e.g.

TestMessage msg = TestMessage.newBuilder().setTestString( "a string with 
'single quotes'").build()
String serialized = JsonFormat.printToString(msg);

3. The serialized string will look like the following:
{ "test_string":"a string with \'single quotes\'" }

But according to the JSON spec (http://www.json.org/), a single quote is not a 
valid symbol to follow a reverse solidus (single quotes don't need to be 
escaped at all in JSON). Trying to deserialize this through any 
standards-compilant JSON parser (e.g. Jackson) will result an error related to 
the fact that \' is not a valid character in JSON-encoded data.

What is the expected output? What do you see instead?
For syntactically-valid / standards-compliant JSON, I would expect to see 
instead
{ "test_string":"a string with 'single quotes'" }

[note the lack of reverse solidus before the single quotes.]

What version of the product are you using? On what operating system?
OS X 10.6, library version 1.1, Jackson 1.5.4

Thanks.

Original issue reported on code.google.com by rosenblu...@gmail.com on 29 Jun 2010 at 4:01

GoogleCodeExporter commented 8 years ago
This is fixed with patch to issue 11 (patch needs slight modifications though).

Original comment by philippe...@obiba.org on 4 Apr 2011 at 7:22

GoogleCodeExporter commented 8 years ago

Original comment by eliran.bivas on 21 Apr 2011 at 2:33