From 2db6795a1aae8326ad5c98def421e6e7b94dc277 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 13 Dec 2021 21:03:28 +0000 Subject: [PATCH] Polishing contribution Closes gh-27722 --- .../messaging/simp/stomp/StompDecoder.java | 11 +++++++---- .../messaging/simp/stomp/StompDecoderTests.java | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index 66206f667953..b22e91154b53 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -143,7 +143,7 @@ private Message decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValu 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 @@ private String readCommand(ByteBuffer byteBuffer) { 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; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompDecoderTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompDecoderTests.java index b0797dc6c171..d8cb23d02db3 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompDecoderTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompDecoderTests.java @@ -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 void decodeFrameWithEscapedHeaders() { 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";