Skip to content

Commit e60e8dc

Browse files
committed
Fix issue with getting SockJS path
Issue: SPR-10923
1 parent 6ddacdc commit e60e8dc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private String getSockJsPath(ServerHttpRequest request) {
374374
// Try SockJS prefix hints
375375
if (!this.validSockJsPrefixes.isEmpty()) {
376376
for (String prefix : this.validSockJsPrefixes) {
377-
int index = path.indexOf(prefix);
377+
int index = path.lastIndexOf(prefix);
378378
if (index != -1) {
379379
this.knownSockJsPrefixes.add(path.substring(0, index + prefix.length()));
380380
return path.substring(index + prefix.length());

spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/AbstractSockJsServiceTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ public void getSockJsPathForTransportRequestWithConfiguredPrefix() throws Except
113113
assertSame(this.handler, this.service.handler);
114114
}
115115

116+
// SPR-10923
117+
118+
@Test
119+
public void getSockJsPathWithPartlyMatchingServletPath() throws Exception {
120+
121+
this.service.setValidSockJsPrefixes("/snake");
122+
handleRequest("GET", "/snakedemo/snake/info", HttpStatus.OK);
123+
124+
assertTrue(this.servletResponse.getContentAsString().startsWith("{\"entropy\":"));
125+
}
126+
116127
@Test
117128
public void validateRequest() throws Exception {
118129

@@ -146,7 +157,7 @@ public void handleInfoGet() throws Exception {
146157

147158
String body = this.servletResponse.getContentAsString();
148159
assertEquals("{\"entropy\"", body.substring(0, body.indexOf(':')));
149-
assertEquals(",\"origins\":[\"*:*\"],\"cookie_needed\":false,\"websocket\":true}",
160+
assertEquals(",\"origins\":[\"*:*\"],\"cookie_needed\":true,\"websocket\":true}",
150161
body.substring(body.indexOf(',')));
151162

152163
this.service.setSessionCookieNeeded(false);

0 commit comments

Comments
 (0)