mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 22:19:03 +00:00
Support multi-line comments in Server Sent Events
Prior to this commit, comments sent with Server Sent Events could break the wire format when sent over the network when comments contained line breaks. While comments are mainly used for sending keepalive messages, they can also be used for sending debug data. This commit ensures that line breaks are properly handled in comments. Fixes gh-36866
This commit is contained in:
@@ -22,6 +22,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
@@ -44,6 +45,15 @@ class ServerSentEventTests {
|
||||
ServerSentEvent.<String>builder().event("first" + newLine + "second").build());
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest(name = "{1}")
|
||||
@MethodSource("newLineCharacters")
|
||||
void supportMultiLineComments(String newLine, String description) {
|
||||
ServerSentEvent<String> event = ServerSentEvent.<String>builder()
|
||||
.comment("foo" + newLine + "bar" + newLine + "baz").data("payload").build();
|
||||
assertThat(event.format()).isEqualTo(":foo\n:bar\n:baz\ndata:");
|
||||
}
|
||||
|
||||
private static Stream<Arguments> newLineCharacters() {
|
||||
return Stream.of(
|
||||
Arguments.of("\n", "LF"),
|
||||
|
||||
Reference in New Issue
Block a user