-
Notifications
You must be signed in to change notification settings - Fork 183
Add escape output parameter #4179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -861,14 +861,21 @@ public void testValidateFields_InvalidCharacterSet() { | |
@Test | ||
public void prepareJsonValue_returnsRawIfJson() { | ||
String json = "{\"key\": 123}"; | ||
String result = StringUtils.prepareJsonValue(json); | ||
String result = StringUtils.prepareJsonValue(json, false); | ||
assertSame(json, result); // branch where isJson(input)==true | ||
} | ||
|
||
@Test | ||
public void prepareJsonValue_returnEscapeJsonIfForce() { | ||
String json = "{\"key\": 123}"; | ||
String result = StringUtils.prepareJsonValue(json, true); | ||
assertEquals("{\\\"key\\\": 123}", result); | ||
} | ||
|
||
@Test | ||
public void prepareJsonValue_escapesBadCharsOtherwise() { | ||
String input = "Tom & Jerry \"<script>"; | ||
String escaped = StringUtils.prepareJsonValue(input); | ||
String escaped = StringUtils.prepareJsonValue(input, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is misleading here, you are actually escaping the plain text, but passing "escape" parameter as false. May be rename "escape" parameter in the API definition, which should understand it is only about json string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sense, i will update it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename it to |
||
assertNotEquals(input, escaped); | ||
assertFalse(StringUtils.isJson(escaped)); | ||
assertEquals("Tom & Jerry \\\"<script>", escaped); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to change API documentation based on new behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, the documentation need update as well