GlowPod / 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

JsonFormat.escapeBytes() produces invalid escape sequences '\a' and '\v' in generated JSON for bytes fields #18

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. Define any message with a bytes field.
2. Create an instance of that message with that field set to a value that 
contains bytes 0x07 or 0x0b
3. Call JsonFormat.printToString. The generated JSON will contain a string 
value for this field with the tokens \a and \v in this value. This is invalid 
JSON according to the JSON spec (http://www.json.org/) because 'a' and 'v' are 
not amongst the characters that are allowed to follow a reverse solidus. No 
standards-compliant JSON parser (e.g. Jackson) or validator (e.g. 
www.jsonlint.org) will parse this JSON.

These escapes are explicitly added by the method JsonFormat.escapeBytes(). It's 
unclear why \a and \v need special handling rather than just being turned into 
unicode characters.

Environment:
* JsonFormat 1.1 (though the head of the current source (r. 34) currently has 
this issue as well)
* OS X 10.6.4
* Java:
** java version "1.6.0_20"
** Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
** Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)
* Jackson 1.5.4 (though any other standards-compliant parser will fail to parse 
this as well, e.g. www.jsonlint.org)

Original issue reported on code.google.com by rosenblu...@gmail.com on 31 Jul 2010 at 7:22

GoogleCodeExporter commented 8 years ago
This is fixed with patch for issue 11

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

GoogleCodeExporter commented 8 years ago

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