Skip to content

Commit d09104d

Browse files
Decode webhook request body as UTF-8 (#763)
When receiving a webhook request at bitbucket-scmsource-hook and converting the HTTP request body to a string, always use UTF-8 even if the system default charset is different. This is mainly relevant to a Jenkins controller running on Windows, where the system charset might be Windows-1252, but Bitbucket Server encodes the webhook request JSON in UTF-8. Fix <https://github.com/jenkinsci/bitbucket-branch-source-plugin/issues/762>
1 parent 8864519 commit d09104d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/BitbucketSCMSourcePushHookReceiver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import hudson.security.csrf.CrumbExclusion;
2929
import hudson.util.HttpResponses;
3030
import java.io.IOException;
31+
import java.nio.charset.StandardCharsets;
3132
import java.util.logging.Level;
3233
import java.util.logging.Logger;
3334
import javax.servlet.FilterChain;
@@ -77,7 +78,7 @@ public String getUrlName() {
7778
*/
7879
public HttpResponse doNotify(StaplerRequest req) throws IOException {
7980
String origin = SCMEvent.originOf(req);
80-
String body = IOUtils.toString(req.getInputStream());
81+
String body = IOUtils.toString(req.getInputStream(), StandardCharsets.UTF_8);
8182
String eventKey = req.getHeader("X-Event-Key");
8283
if (eventKey == null) {
8384
return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST, "X-Event-Key HTTP header not found");

0 commit comments

Comments
 (0)