LANG-1396 - JsonToStringStyle does not escape string names

This commit is contained in:
Sebb 2018-05-10 13:08:07 +01:00
parent e7d16c2762
commit 3fadfdd69f
3 changed files with 7 additions and 1 deletions

View File

@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.8" date="2018-MM-DD" description="New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.">
<action issue="LANG-1396" type="fix" dev="sebb">JsonToStringStyle does not escape string names</action>
<action issue="LANG-1395" type="fix" dev="sebb" due=to="Jim Gan">JsonToStringStyle does not escape double quote in a string value</action>
<action issue="LANG-1384" type="fix" dev="erans" due-to="Ian Young">New Java version ("11") must be handled</action>
<action issue="LANG-1364" type="fix" dev="pschumacher" due-to="Zheng Xie">ExceptionUtils#getRootCause(Throwable t) should return t if no lower level cause exists</action>

View File

@ -2619,7 +2619,7 @@ protected void appendFieldStart(final StringBuffer buffer, final String fieldNam
"Field names are mandatory when using JsonToStringStyle");
}
super.appendFieldStart(buffer, FIELD_NAME_QUOTE + fieldName
super.appendFieldStart(buffer, FIELD_NAME_QUOTE + StringEscapeUtils.escapeJson(fieldName)
+ FIELD_NAME_QUOTE);
}

View File

@ -387,6 +387,11 @@ public void testLANG1395() {
assertEquals("{\"name\":\"Let's \\\"quote\\\" this\"}",new ToStringBuilder(base).append("name","Let's \"quote\" this").toString());
}
@Test
public void testLANG1396() {
assertEquals("{\"Let's \\\"quote\\\" this\":\"value\"}",new ToStringBuilder(base).append("Let's \"quote\" this","value").toString());
}
/**
* An object with nested object structures used to test {@link ToStringStyle.JsonToStringStyle}.
*