Use the character encoding of the request or UTF-8 if no character encoding is available for decoding the request body of a web hook (fixes #308)

This commit is contained in:
Robin Müller 2016-05-11 08:55:25 +02:00
parent 358b4f229f
commit 32cd71c119
1 changed files with 4 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.StaplerResponse;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -29,6 +30,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static com.dabsquared.gitlabjenkins.util.LoggerUtil.toArray; import static com.dabsquared.gitlabjenkins.util.LoggerUtil.toArray;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* @author Robin Müller * @author Robin Müller
@ -103,7 +105,8 @@ public class ActionResolver {
private String getRequestBody(StaplerRequest request) { private String getRequestBody(StaplerRequest request) {
String requestBody; String requestBody;
try { try {
requestBody = IOUtils.toString(request.getInputStream()); Charset charset = request.getCharacterEncoding() == null ? UTF_8 : Charset.forName(request.getCharacterEncoding());
requestBody = IOUtils.toString(request.getInputStream(), charset);
} catch (IOException e) { } catch (IOException e) {
throw HttpResponses.error(500, "Failed to read request body"); throw HttpResponses.error(500, "Failed to read request body");
} }