From fea8bb794dd85605b2c429ef41a505cc39361dc5 Mon Sep 17 00:00:00 2001 From: Lachlan Date: Thu, 24 Oct 2019 08:24:19 +1100 Subject: [PATCH] Issue #4240 - use default charset utf-8 for cgi request form encoding (#4241) Signed-off-by: Lachlan Roberts --- .../src/main/java/org/eclipse/jetty/servlets/CGI.java | 7 ++++++- .../test-jetty-webapp/src/main/webapp/WEB-INF/web.xml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java index eab8186d5fa..bcadd367044 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java @@ -25,6 +25,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; @@ -251,7 +252,11 @@ public class CGI extends HttpServlet String parameterName = names.nextElement(); parameterMap.addValues(parameterName, req.getParameterValues(parameterName)); } - bodyFormEncoded = UrlEncoded.encode(parameterMap, Charset.forName(req.getCharacterEncoding()), true); + + String characterEncoding = req.getCharacterEncoding(); + Charset charset = characterEncoding != null + ? Charset.forName(characterEncoding) : StandardCharsets.UTF_8; + bodyFormEncoded = UrlEncoded.encode(parameterMap, charset, true); } EnvList env = new EnvList(_env); diff --git a/tests/test-webapps/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml b/tests/test-webapps/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml index 75523dfb47a..05e4f1d4f6f 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml +++ b/tests/test-webapps/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml @@ -125,6 +125,7 @@ CGI org.eclipse.jetty.servlets.CGI 1 + true