-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix json-body not escaping special characters #2551
Conversation
1822bb2
to
1d29977
Compare
} | ||
|
||
@Test | ||
public void test2() { |
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.
Super small minor thing but I was wondering if we could add a more targeted name for this test?
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.
This test is not really needed. I had it for my local testing. 😅
} | ||
|
||
private byte[] base64Encode(String string) { | ||
return Base64.getEncoder().encode(string.getBytes(StandardCharsets.UTF_8)); |
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.
There is already some encoding support in Wiremock here. Not sure if there is any value to using that here ?
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.
Reused existing encoding functions.
This looks great. Appreciate the comprehensive tests. Just a few small comments really. I was also thinking it might be nice to add a few examples with this kind of escaping to the website here - https://github.com/wiremock/wiremock.org |
@leeturner thank you for the suggestion. But if you still think that documentation is needed, let me know where in the doc this information will best fit. |
Thank you for the updates. We just need Tom to cast his eyes over it and then we can take it from there |
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.
Looks great. Really appreciate your contribution
This pull request fixes json-body not escaping special characters.
When Response-Body object is constructed from JSON file, it is stored as byte-array (plain text). So, the escape sequences are never replaced with their correct representation. They remain as is.
This creates problem when the JSON has special meaning after escaping. Such as the issue reported in : #2547
References
JsonNode
of Jackson offers a methodasText()
which return the actual value ofValueNode
. This will return a escaped string for aTextNode
JsonNode#asText()
Body
which stores the parsed JSON-nodes. This helps to avoid converting between escaped and non-escaped string many times.Body
are modified to store the escaped JSON string when necessary.Submitter checklist
#help-contributing
or a project-specific channel like#wiremock-java