From 8047d360285248122cb8dbb5e13d19e617859b6d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 3 Apr 2018 11:00:16 +0200 Subject: [PATCH] #970 use iso-8859-1 for http post args instead of us-ascii --- .../main/java/sonia/scm/web/WireProtocol.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/WireProtocol.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/WireProtocol.java index 8a411ead64..fb84692805 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/WireProtocol.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/WireProtocol.java @@ -119,14 +119,7 @@ public final class WireProtocol { if (request instanceof HgServletRequest) { HgServletRequest hgRequest = (HgServletRequest) request; - try { - byte[] bytes = hgRequest.getInputStream().readAndCapture(hgArgsPostSize); - String hgArgs = new String(bytes, Charsets.US_ASCII); - String decoded = decodeValue(hgArgs); - parseHgCommandHeader(listOfCmds, decoded); - } catch (IOException ex) { - throw Throwables.propagate(ex); - } + parseHttpPostArgs(listOfCmds, hgArgsPostSize, hgRequest); } else { throw new IllegalArgumentException("could not process the httppostargs protocol without HgServletRequest"); } @@ -134,6 +127,19 @@ public final class WireProtocol { } } + private static void parseHttpPostArgs(List listOfCmds, int hgArgsPostSize, HgServletRequest hgRequest) { + try { + byte[] bytes = hgRequest.getInputStream().readAndCapture(hgArgsPostSize); + // we use iso-8859-1 for encoding, because the post args are normally http headers which are using iso-8859-1 + // see https://tools.ietf.org/html/rfc7230#section-3.2.4 + String hgArgs = new String(bytes, Charsets.ISO_8859_1); + String decoded = decodeValue(hgArgs); + parseHgCommandHeader(listOfCmds, decoded); + } catch (IOException ex) { + throw Throwables.propagate(ex); + } + } + private static void parseHgArgHeaders(HttpServletRequest request, List listOfCmds) { Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) {