@@ -56,6 +56,13 @@ public function testParseDataWithCarrigeReturnAndNewlineOverTwoLines()
5656 $ this ->assertEquals ("hello \n" , $ message ->data );
5757 }
5858
59+ public function testParseDataWithNonUtf8AndNullBytesReturnsDataWithUnicodeReplacement ()
60+ {
61+ $ message = MessageEvent::parse ("data: h \x00ll \xFF! " , '' );
62+
63+ $ this ->assertEquals ("h \x00ll�! " , $ message ->data );
64+ }
65+
5966 public function testParseReturnsMessageWithIdFromStream ()
6067 {
6168 $ message = MessageEvent::parse ("data: hello \r\nid: 1 " , '' );
@@ -88,6 +95,22 @@ public function testParseWithMultipleIdsReturnsMessageWithLastEventIdFromStream(
8895 $ this ->assertEquals ('2 ' , $ message ->lastEventId );
8996 }
9097
98+ public function testParseWithIdWithNonUtf8BytesReturnsMessageWithLastEventIdFromStreamWithUnicodeReplacement ()
99+ {
100+ $ message = MessageEvent::parse ("data: hello \nid: h \xFFllo! " , '' );
101+
102+ $ this ->assertEquals ("hello " , $ message ->data );
103+ $ this ->assertEquals ("h�llo! " , $ message ->lastEventId );
104+ }
105+
106+ public function testParseWithIdWithNullByteReturnsMessageWithLastEventIdFromLastEventId ()
107+ {
108+ $ message = MessageEvent::parse ("data: hello \nid: h \x00llo! " , '1 ' );
109+
110+ $ this ->assertEquals ("hello " , $ message ->data );
111+ $ this ->assertEquals ('1 ' , $ message ->lastEventId );
112+ }
113+
91114 public function testParseReturnsMessageWithTypeFromStream ()
92115 {
93116 $ message = MessageEvent::parse ("data: hello \r\nevent: join " , '' );
@@ -120,6 +143,14 @@ public function testParseWithEmptyEventReturnsMessageWithDefaultMessageType()
120143 $ this ->assertEquals ('message ' , $ message ->type );
121144 }
122145
146+ public function testParseWithEventTypeWithNonUtf8AndNullBytesReturnsTypeWithUnicodeReplacement ()
147+ {
148+ $ message = MessageEvent::parse ("data: hello \nevent: h \x00ll \xFF! " , '' );
149+
150+ $ this ->assertEquals ("hello " , $ message ->data );
151+ $ this ->assertEquals ("h \x00ll�! " , $ message ->type );
152+ }
153+
123154 public function retryTimeDataProvider ()
124155 {
125156 return [
0 commit comments