Skip to content

Commit 7b36558

Browse files
committed
Merge pull request from jking-roar/SPR-13111
2 parents c41779f + 1153969 commit 7b36558

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -215,10 +215,10 @@ private void readHeaders(ByteBuffer buffer, StompHeaderAccessor headerAccessor)
215215
if (headerStream.size() > 0) {
216216
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
217217
int colonIndex = header.indexOf(':');
218-
if (colonIndex <= 0 || colonIndex == header.length() - 1) {
219-
if (buffer.remaining() > 0) {
218+
if (colonIndex <= 0) {
219+
if(buffer.remaining() > 0) {
220220
throw new StompConversionException("Illegal header: '" + header +
221-
"'. A header must be of the form <name>:<value>.");
221+
"'. A header must be of the form <name>:[<value>].");
222222
}
223223
}
224224
else {

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -176,18 +176,32 @@ public void decodeMultipleFramesFromSameBuffer() {
176176
Buffer buffer = Buffer.wrap(frame1 + frame2);
177177

178178
final List<Message<byte[]>> messages = new ArrayList<Message<byte[]>>();
179-
new Reactor2StompCodec().decoder(new Consumer<Message<byte[]>>() {
180-
@Override
181-
public void accept(Message<byte[]> message) {
182-
messages.add(message);
183-
}
184-
}).apply(buffer);
179+
new Reactor2StompCodec().decoder(messages::add).apply(buffer);
185180

186181
assertEquals(2, messages.size());
187182
assertEquals(StompCommand.SEND, StompHeaderAccessor.wrap(messages.get(0)).getCommand());
188183
assertEquals(StompCommand.DISCONNECT, StompHeaderAccessor.wrap(messages.get(1)).getCommand());
189184
}
190185

186+
// SPR-13111
187+
188+
@Test
189+
public void decodeFrameWithHeaderWithEmptyValue() {
190+
String accept = "accept-version:1.1\n";
191+
String valuelessKey = "key:\n";
192+
193+
Message<byte[]> frame = decode("CONNECT\n" + accept + valuelessKey + "\n\0");
194+
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
195+
196+
assertEquals(StompCommand.CONNECT, headers.getCommand());
197+
198+
assertEquals(2, headers.toNativeHeaderMap().size());
199+
assertEquals("1.1", headers.getFirstNativeHeader("accept-version"));
200+
assertEquals("", headers.getFirstNativeHeader("key"));
201+
202+
assertEquals(0, frame.getPayload().length);
203+
}
204+
191205
@Test
192206
public void decodeFrameWithIncompleteCommand() {
193207
assertIncompleteDecode("MESSAG");
@@ -234,12 +248,7 @@ public void decodeHeartbeat() {
234248
Buffer buffer = Buffer.wrap(frame);
235249

236250
final List<Message<byte[]>> messages = new ArrayList<Message<byte[]>>();
237-
new Reactor2StompCodec().decoder(new Consumer<Message<byte[]>>() {
238-
@Override
239-
public void accept(Message<byte[]> message) {
240-
messages.add(message);
241-
}
242-
}).apply(buffer);
251+
new Reactor2StompCodec().decoder(messages::add).apply(buffer);
243252

244253
assertEquals(1, messages.size());
245254
assertEquals(SimpMessageType.HEARTBEAT, StompHeaderAccessor.wrap(messages.get(0)).getMessageType());

0 commit comments

Comments
 (0)