Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public StringBuilder toJsonString(StringBuilder buf, Charset charset) {
if (i > 0) {
buf.append(", ");
}
buf.append('"').append(key(i, charset)).append('"');
buf.append('"').append(escapse(key(i, charset))).append('"');
buf.append(": ");
element(i, charset).toJsonString(buf, charset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.taobao.tddl.dbsync.binlog.JsonConversion.Json_Value;
import com.taobao.tddl.dbsync.binlog.JsonConversion.Json_enum_type;

import java.nio.charset.Charset;

public class JsonConversion_Json_ValueTest {

@Rule
Expand Down Expand Up @@ -51,4 +53,27 @@ public void parse_valueInputZeroNotNullPositiveNotNullOutputIllegalArgumentExcep

// Method is not expected to return due to exception thrown
}

// test for 5127
@Test
public void testJsonKeyContainsSpecialCharacter() {

// {"internal_uri_rewrite": {"(.*)(/[^/]+\\.(mp|MP)4)$": "$1/mp4$2"}}
String jsonData = "{\"internal_uri_rewrite\": {\"(.*)(/[^/]+\\\\.(mp|MP)4)$\": \"$1/mp4$2\"}}";
byte[] data = new byte[]{1, 0, 74, 0, 11, 0, 20, 0, 0, 31, 0, 105, 110, 116, 101, 114, 110, 97, 108, 95, 117, 114, 105, 95, 114, 101, 119, 114, 105, 116, 101, 1, 0, 43, 0, 11, 0, 23, 0, 12, 34, 0, 40, 46, 42, 41, 40, 47, 91, 94, 47, 93, 43, 92, 46, 40, 109, 112, 124, 77, 80, 41, 52, 41, 36, 8, 36, 49, 47, 109, 112, 52, 36, 50};
final LogBuffer buffer = new LogBuffer(data, 0, 74);

Charset charset = Charset.forName("UTF-8");
Json_Value jsonValue = JsonConversion.parse_value(0, buffer, 74, charset);
StringBuilder builder = new StringBuilder();
jsonValue.toJsonString(builder, charset);


Assert.assertEquals(builder.toString(), jsonData);

Assert.assertEquals(jsonValue.key(0, charset), "internal_uri_rewrite");

Json_Value element = jsonValue.element(0, charset);
Assert.assertEquals(element.key(0, charset), "(.*)(/[^/]+\\.(mp|MP)4)$");
}
}