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

com.googlecode.protobuf.format.JsonFormat#escapeBytes handles '\a' incorrectly. '\a' is ivalid value for json. #45

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
simple code example

import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import com.googlecode.protobuf.format.JsonFormat;
import com.viaden.network.yoga.core.api.YogaCoreDomain;

/**
 * protobuf message
 * <p/>
 * {@code message TestObject { required bytes data = 1; }}
 */
public class JacksonTest {

    private static final char BELL_CHARACTER = '\u0007';

    public static void main(String[] args) throws Exception {
        final YogaCoreDomain.TestObject.Builder testObject = YogaCoreDomain.TestObject.newBuilder();
        testObject.setData(ByteString.copyFrom(new byte[]{BELL_CHARACTER}));

        final Message.Builder builder = YogaCoreDomain.TestObject.getDefaultInstance().newBuilderForType();
        final String result = JsonFormat.printToString(builder.mergeFrom(testObject.build()).build());
    }
}

What is the expected output? What do you see instead?
expected:
{"data":"\u0007"}
actual
{"data":"\a"}

What version of the product are you using? On what operating system?
1.2

Please provide any additional information below.

Original issue reported on code.google.com by korolyov...@gmail.com on 22 Jan 2013 at 12:23

GoogleCodeExporter commented 8 years ago
Right, \a is used by protobuf text format for printing human readable messages, 
but this is not one of recognized special symbols in json (such as \t for 
example) - see json formal grammar on json.org

Original comment by aleksey....@viaden.com on 22 Jan 2013 at 12:31

GoogleCodeExporter commented 8 years ago
Just noticed that there's similar issue 
http://code.google.com/p/protobuf-java-format/issues/detail?id=43
This may be resolve as duplicate.

Original comment by aleksey....@viaden.com on 22 Jan 2013 at 12:39

GoogleCodeExporter commented 8 years ago
had a similar issue here, we are using bytes type for some fields in the proto, 
but when converting to json with protobuf-java-format, we found the string 
content is not properly escaped and json parsers give invalid json errors.

is it possible to fix this and release a new version?

Original comment by guozheng...@gmail.com on 6 Aug 2015 at 11:58