Browse Source

Polishing contribution

Closes gh-27722
pull/27818/head
Rossen Stoyanchev 4 years ago
parent
commit
2db6795a1a
  1. 11
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java
  2. 4
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompDecoderTests.java

11
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

@ -143,7 +143,7 @@ public class StompDecoder { @@ -143,7 +143,7 @@ public class StompDecoder {
StompCommand stompCommand = StompCommand.valueOf(command);
headerAccessor = StompHeaderAccessor.create(stompCommand);
initHeaders(headerAccessor);
readHeaders(stompCommand, byteBuffer, headerAccessor);
readHeaders(byteBuffer, headerAccessor, stompCommand);
payload = readPayload(byteBuffer, headerAccessor);
}
if (payload != null) {
@ -215,9 +215,12 @@ public class StompDecoder { @@ -215,9 +215,12 @@ public class StompDecoder {
return StreamUtils.copyToString(command, StandardCharsets.UTF_8);
}
private void readHeaders(StompCommand stompCommand, ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) {
boolean shouldUnescape = (stompCommand != StompCommand.CONNECT && stompCommand != StompCommand.STOMP
&& stompCommand != StompCommand.CONNECTED);
private void readHeaders(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor, StompCommand command) {
boolean shouldUnescape = (command != StompCommand.CONNECT &&
command != StompCommand.CONNECTED &&
command != StompCommand.STOMP);
while (true) {
ByteArrayOutputStream headerStream = new ByteArrayOutputStream(256);
boolean headerComplete = false;

4
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompDecoderTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -159,7 +159,7 @@ public class StompDecoderTests { @@ -159,7 +159,7 @@ public class StompDecoderTests {
assertThat(headers.getFirstNativeHeader("a:\r\n\\b")).isEqualTo("alpha:bravo\r\n\\");
}
@Test
@Test // gh-27722
public void decodeFrameWithHeaderWithBackslashValue() {
String accept = "accept-version:1.1\n";
String keyAndValueWithBackslash = "key:\\value\n";

Loading…
Cancel
Save