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: Exclude Javascript and JSON from parsing for charsets from forms by proxy
Date Sat, 08 Aug 2020 17:37:08 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 81a6d67  Exclude Javascript and JSON from parsing for charsets from forms by proxy
81a6d67 is described below

commit 81a6d678d725e98d5325b8d9429345f40d35f845
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Sat Aug 8 19:31:22 2020 +0200

    Exclude Javascript and JSON from parsing for charsets from forms by proxy
    
    JSoup currently has problems parsing some non HTML code - for which
    it was probably never intended. So skip known not HTML resources
    in the proxy recording logic, when character encodings for forms
    are extracted.
    
    Bugzilla Id: 64653
---
 .../apache/jmeter/protocol/http/proxy/Proxy.java    | 21 ++++++++++++++++++++-
 xdocs/changes.xml                                   |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java
index 5648904..bda8a6e 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java
@@ -32,6 +32,7 @@ import java.security.GeneralSecurityException;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -63,6 +64,9 @@ import org.slf4j.LoggerFactory;
  * JMeter test plan.
  */
 public class Proxy extends Thread {
+    // Mime-types of resources, that are not HTML and not binary that should be skipped on
form parsing in JSoup
+    private static final List<String> NOT_HTML_TEXT_TYPES = Arrays.asList("application/javascript",
"application/json", "text/javascript");
+
     private static final Logger log = LoggerFactory.getLogger(Proxy.class);
 
     private static final byte[] CRLF_BYTES = { 0x0d, 0x0a };
@@ -595,10 +599,16 @@ public class Proxy extends Thread {
         FormCharSetFinder finder = new FormCharSetFinder();
         if (SampleResult.isBinaryType(result.getContentType())) {
             if (log.isDebugEnabled()) {
-                log.debug("Will not guess encoding of url:{} as it's binary", result.getUrlAsString());
+                log.debug("Will not guess encoding of URL: {} as it's binary", result.getUrlAsString());
             }
             return; // no point parsing anything else, e.g. GIF ...
         }
+        if (isNotHtmlType(result.getContentType())) {
+            if (log.isDebugEnabled()) {
+                log.debug("Will not guess encoding of URL: {} as it's not HTML", result.getUrlAsString());
+            }
+            return; // None HTML types have been crashing JSoup parser, so return here early
+        }
         try {
             finder.addFormActionsAndCharSet(result.getResponseDataAsString(), formEncodings,
pageEncoding);
         }
@@ -609,6 +619,15 @@ public class Proxy extends Thread {
         }
     }
 
+    private boolean isNotHtmlType(String contentType) {
+        for (String mimeType: NOT_HTML_TEXT_TYPES) {
+            if (contentType.startsWith(mimeType)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private String getUrlWithoutQuery(URL url) {
         String fullUrl = url.toString();
         String urlWithoutQuery = fullUrl;
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index d297eb0..014db1c 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -136,6 +136,7 @@ Summary
 <h3>HTTP Samplers and Test Script Recorder</h3>
 <ul>
   <li><bug>64479</bug>Regression: HTTP(s) Script Recorder prevents proper
shutdown in non-GUI mode</li>
+  <li><bug>64653</bug>Exclude Javascript and JSON from parsing for charsets
from forms by proxy</li>
 </ul>
 
 <h3>Other Samplers</h3>


Mime
View raw message