Skip to content

Commit

Permalink
AVRO-851. Java: Fix a bug in GenericData#toString() when escaping cha…
Browse files Browse the repository at this point in the history
…racters. Contributed by Jeff Mesnil.

git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1384500 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cutting committed Sep 13, 2012
1 parent a4994fd commit c078153
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -49,6 +49,9 @@ Avro 1.7.2 (unreleased)
AVRO-1155. Stringable Date test in TestReflect fails if timezone doesn't
match locale's default. Removed Date from built-in stringables. (tomwhite)

AVRO-851. Java: Fix a bug in GenericData#toString() when escaping
characters. (Jeff Mesnil via cutting)

Avro 1.7.1 (16 July 2012)

NEW FEATURES
Expand Down
Expand Up @@ -445,9 +445,9 @@ private void writeEscapedString(String string, StringBuilder builder) {
if((ch>='\u0000' && ch<='\u001F') || (ch>='\u007F' && ch<='\u009F') || (ch>='\u2000' && ch<='\u20FF')){
String hex = Integer.toHexString(ch);
builder.append("\\u");
for(int j = 0; j < 4-builder.length(); j++)
for(int j = 0; j < 4 - hex.length(); j++)
builder.append('0');
builder.append(string.toUpperCase());
builder.append(hex.toUpperCase());
} else {
builder.append(ch);
}
Expand Down
Expand Up @@ -305,7 +305,8 @@ public void testToStringIsJson() throws JsonParseException, IOException {
schema.setFields(Arrays.asList(stringField, enumField));

GenericRecord r = new GenericData.Record(schema);
r.put(stringField.name(), "hello\nthere\"\tyou}");
// \u2013 is EN DASH
r.put(stringField.name(), "hello\nthere\"\tyou\u2013}");
r.put(enumField.name(), new GenericData.EnumSymbol(enumField.schema(),"a"));

String json = r.toString();
Expand Down

0 comments on commit c078153

Please sign in to comment.