vlsi commented on a change in pull request #660:
URL: https://github.com/apache/jmeter/pull/660#discussion_r749098019
##########
File path:
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java
##########
@@ -79,28 +80,24 @@ public static boolean isGraphQLContentType(final String
contentType) {
* @throws RuntimeException if JSON serialization fails for some reason
due to any runtime environment issues
*/
public static String toPostBodyString(final GraphQLRequestParams params) {
- final ObjectMapper mapper = new ObjectMapper();
- final ObjectNode postBodyJson = mapper.createObjectNode();
- postBodyJson.set(OPERATION_NAME_FIELD,
-
JsonNodeFactory.instance.textNode(StringUtils.trimToNull(params.getOperationName())));
+ final StringBuilder sb = new StringBuilder(1024);
+
+ sb.append("{");
+
+ appendJsonStringField(sb, OPERATION_NAME_FIELD,
StringUtils.trimToNull(params.getOperationName()));
+ sb.append(",");
if (StringUtils.isNotBlank(params.getVariables())) {
- try {
- final ObjectNode variablesJson =
mapper.readValue(params.getVariables(), ObjectNode.class);
- postBodyJson.set(VARIABLES_FIELD, variablesJson);
- } catch (JsonProcessingException e) {
- log.error("Ignoring the GraphQL query variables content due to
the syntax error: {}",
- e.getLocalizedMessage());
- }
+ sb.append("\"").append(VARIABLES_FIELD).append("\":");
+ sb.append(StringUtils.trim(params.getVariables()));
+ sb.append(",");
}
- postBodyJson.set(QUERY_FIELD,
JsonNodeFactory.instance.textNode(StringUtils.trim(params.getQuery())));
+ appendJsonStringField(sb, QUERY_FIELD,
escapeNewLinesForJson(StringUtils.trim(params.getQuery())));
Review comment:
Why only newlines are escaped? What if the value contains quotes,
slashes, or something else?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]