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 d279aa59e8..ab8201a48b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -215,10 +215,10 @@ public class StompDecoder { if (headerStream.size() > 0) { String header = new String(headerStream.toByteArray(), UTF8_CHARSET); int colonIndex = header.indexOf(':'); - if (colonIndex <= 0 || colonIndex == header.length() - 1) { - if (buffer.remaining() > 0) { + if (colonIndex <= 0) { + if(buffer.remaining() > 0) { throw new StompConversionException("Illegal header: '" + header + - "'. A header must be of the form :."); + "'. A header must be of the form :[]."); } } else { diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompCodecTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompCodecTests.java index dce4e85f64..3da0df98f9 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompCodecTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompCodecTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -176,18 +176,32 @@ public class StompCodecTests { Buffer buffer = Buffer.wrap(frame1 + frame2); final List> messages = new ArrayList>(); - new Reactor2StompCodec().decoder(new Consumer>() { - @Override - public void accept(Message message) { - messages.add(message); - } - }).apply(buffer); + new Reactor2StompCodec().decoder(messages::add).apply(buffer); assertEquals(2, messages.size()); assertEquals(StompCommand.SEND, StompHeaderAccessor.wrap(messages.get(0)).getCommand()); assertEquals(StompCommand.DISCONNECT, StompHeaderAccessor.wrap(messages.get(1)).getCommand()); } + // SPR-13111 + + @Test + public void decodeFrameWithHeaderWithEmptyValue() { + String accept = "accept-version:1.1\n"; + String valuelessKey = "key:\n"; + + Message frame = decode("CONNECT\n" + accept + valuelessKey + "\n\0"); + StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); + + assertEquals(StompCommand.CONNECT, headers.getCommand()); + + assertEquals(2, headers.toNativeHeaderMap().size()); + assertEquals("1.1", headers.getFirstNativeHeader("accept-version")); + assertEquals("", headers.getFirstNativeHeader("key")); + + assertEquals(0, frame.getPayload().length); + } + @Test public void decodeFrameWithIncompleteCommand() { assertIncompleteDecode("MESSAG"); @@ -234,12 +248,7 @@ public class StompCodecTests { Buffer buffer = Buffer.wrap(frame); final List> messages = new ArrayList>(); - new Reactor2StompCodec().decoder(new Consumer>() { - @Override - public void accept(Message message) { - messages.add(message); - } - }).apply(buffer); + new Reactor2StompCodec().decoder(messages::add).apply(buffer); assertEquals(1, messages.size()); assertEquals(SimpMessageType.HEARTBEAT, StompHeaderAccessor.wrap(messages.get(0)).getMessageType());