jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Use less aggressive escaping for JSON Strings in reports error messages
Date Sun, 30 Aug 2020 07:49:12 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 21128b5  Use less aggressive escaping for JSON Strings in reports error messages
21128b5 is described below

commit 21128b56ac4fa1f4d9a260b1f0e4ec3cfa7f033b
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Fri Aug 21 12:53:01 2020 +0200

    Use less aggressive escaping for JSON Strings in reports error messages
    
    Bug 64624
---
 .../org/apache/jmeter/report/dashboard/JsonizerVisitor.java   |  5 +++--
 .../apache/jmeter/report/processor/ErrorsSummaryConsumer.java | 11 +++++++++--
 xdocs/changes.xml                                             |  1 +
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonizerVisitor.java
b/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonizerVisitor.java
index e41f9ec..89b723c 100644
--- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonizerVisitor.java
+++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonizerVisitor.java
@@ -20,13 +20,14 @@ package org.apache.jmeter.report.dashboard;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.commons.text.StringEscapeUtils;
 import org.apache.jmeter.report.core.JsonUtil;
 import org.apache.jmeter.report.processor.ListResultData;
 import org.apache.jmeter.report.processor.MapResultData;
 import org.apache.jmeter.report.processor.ResultData;
 import org.apache.jmeter.report.processor.ResultDataVisitor;
 import org.apache.jmeter.report.processor.ValueResultData;
+
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
 /**
  * The class JsonizerVisitor provides a visitor that can get json-like string
  * from ResultData.
@@ -96,7 +97,7 @@ public class JsonizerVisitor implements ResultDataVisitor<String>
{
             Object value = valueResult.getValue();
             result = String.valueOf(value);
             if (value instanceof String) {
-                result = '"' + StringEscapeUtils.escapeEcmaScript(result.replace('\"', '\''))
+ '"';
+                result = '"' + new String(JsonStringEncoder.getInstance().quoteAsString(result))
+ '"';
             }
         }
         return result;
diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java
b/src/core/src/main/java/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java
index 2264044..f017573 100644
--- a/src/core/src/main/java/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java
+++ b/src/core/src/main/java/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java
@@ -24,6 +24,8 @@ import org.apache.jmeter.report.utils.MetricUtils;
 import org.apache.jmeter.samplers.SampleSaveConfiguration;
 import org.apache.jmeter.util.JMeterUtils;
 
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
+
 /**
  * <p>
  * The class ErrorSummaryConsumer provides a consumer that calculates error
@@ -89,7 +91,7 @@ public class ErrorsSummaryConsumer extends AbstractSummaryConsumer<Long>
{
         String responseCode = sample.getResponseCode();
         String responseMessage = sample.getResponseMessage();
         String key = responseCode + (!StringUtils.isEmpty(responseMessage) ?
-                 "/" + StringEscapeUtils.escapeJson(StringEscapeUtils.escapeHtml4(responseMessage))
: "");
+                 "/" + escapeJson(responseMessage) : "");
         if (MetricUtils.isSuccessCode(responseCode) ||
                 (StringUtils.isEmpty(responseCode) &&
                         !StringUtils.isEmpty(sample.getFailureMessage()))) {
@@ -97,12 +99,17 @@ public class ErrorsSummaryConsumer extends AbstractSummaryConsumer<Long>
{
             if (ASSERTION_RESULTS_FAILURE_MESSAGE) {
                 String msg = sample.getFailureMessage();
                 if (!StringUtils.isEmpty(msg)) {
-                    key = StringEscapeUtils.escapeJson(StringEscapeUtils.escapeHtml4(msg));
+                    key = escapeJson(msg);
                 }
             }
         }
         return key;
     }
+
+    private static String escapeJson(String responseMessage) {
+        return new String(JsonStringEncoder.getInstance().quoteAsString(StringEscapeUtils.escapeHtml4(responseMessage)));
+    }
+
     /*
      * (non-Javadoc)
      *
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index cb0c088..eaa6ebc 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -178,6 +178,7 @@ applications when JMeter is starting up.</p>
 <ul>
     <li><bug>64547</bug>Report/Dashboard: Ensure graphs Response codes
per second is not broken by empty response code in SampleResult. Contributed by Ubik Load
Pack (https://ubikloadpack.com)</li>
     <li><bug>64617</bug>HTML report: In graph Response Time Percentiles
Over Time 90,95,99th percentile correspond in reality to 0.90, 0.95 and 0.99 percentiles</li>
+    <li><bug>64624</bug>Use less aggressive escaping for JSON Strings in
reports error messages</li>
 </ul>
 
 <h3>Documentation</h3>


Mime
View raw message