Skip to content

Commit 82ec06a

Browse files
committed
Fix bug in SockJS JsonpTransportHandler
Issue: SPR-10621
1 parent 2a15b5a commit 82ec06a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/JsonpTransportHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse
6161

6262
@Override
6363
protected String[] readMessages(ServerHttpRequest request) throws IOException {
64-
if (MediaType.APPLICATION_FORM_URLENCODED.equals(request.getHeaders().getContentType())) {
64+
MediaType contentType = request.getHeaders().getContentType();
65+
if ((contentType != null) && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
6566
MultiValueMap<String, String> map = this.formConverter.read(null, request);
6667
String d = map.getFirst("d");
6768
return (StringUtils.hasText(d)) ? getObjectMapper().readValue(d, String[].class) : null;

spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/HttpReceivingTransportHandlerTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ public void readMessagesJsonpFormEncoded() throws Exception {
7373
assertEquals("ok", this.servletResponse.getContentAsString());
7474
}
7575

76+
// SPR-10621
77+
78+
@Test
79+
public void readMessagesJsonpFormEncodedWithEncoding() throws Exception {
80+
this.servletRequest.setContent("d=[\"x\"]".getBytes("UTF-8"));
81+
this.servletRequest.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
82+
handleRequest(new JsonpTransportHandler());
83+
84+
assertEquals(200, this.servletResponse.getStatus());
85+
assertEquals("ok", this.servletResponse.getContentAsString());
86+
}
87+
7688
@Test
7789
public void readMessagesBadContent() throws Exception {
7890
this.servletRequest.setContent("".getBytes("UTF-8"));

0 commit comments

Comments
 (0)