File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
main/java/org/springframework/web/servlet/mvc/method/annotation
test/java/org/springframework/web/servlet/mvc/method/annotation Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -237,6 +237,9 @@ public SseEventBuilder data(Object object) {
237
237
public SseEventBuilder data (Object object , @ Nullable MediaType mediaType ) {
238
238
append ("data:" );
239
239
saveAppendedText ();
240
+ if (object instanceof String text ) {
241
+ object = StringUtils .replace (text , "\n " , "\n data:" );
242
+ }
240
243
this .dataToSend .add (new DataWithMediaType (object , mediaType ));
241
244
append ('\n' );
242
245
return this ;
Original file line number Diff line number Diff line change @@ -104,6 +104,16 @@ public void sendEventWithTwoDataLines() throws Exception {
104
104
this .handler .assertWriteCount (1 );
105
105
}
106
106
107
+ @ Test
108
+ public void sendEventWithMultiline () throws Exception {
109
+ this .emitter .send (event ().data ("foo\n bar\n baz" ));
110
+ this .handler .assertSentObjectCount (3 );
111
+ this .handler .assertObject (0 , "data:" , TEXT_PLAIN_UTF8 );
112
+ this .handler .assertObject (1 , "foo\n data:bar\n data:baz" );
113
+ this .handler .assertObject (2 , "\n \n " , TEXT_PLAIN_UTF8 );
114
+ this .handler .assertWriteCount (1 );
115
+ }
116
+
107
117
@ Test
108
118
public void sendEventFull () throws Exception {
109
119
this .emitter .send (event ().comment ("blah" ).name ("test" ).reconnectTime (5000L ).id ("1" ).data ("foo" ));
You can’t perform that action at this time.
0 commit comments