@@ -96,27 +96,44 @@ public function handleData($data)
9696 $ this ->buffer .= $ data ;
9797
9898 while ($ this ->buffer !== '' ) {
99- // search ESC (\x1B = \033)
100- $ esc = strpos ($ this ->buffer , "\x1B" );
99+ // search for first control character (C0 and DEL)
100+ $ c0 = false ;
101+ for ($ i = 0 ; isset ($ this ->buffer [$ i ]); ++$ i ) {
102+ $ code = ord ($ this ->buffer [$ i ]);
103+ if ($ code < 0x20 || $ code === 0x7F ) {
104+ $ c0 = $ i ;
105+ break ;
106+ }
107+ }
101108
102- // no ESC found, emit whole buffer as data
103- if ($ esc === false ) {
109+ // no C0 found, emit whole buffer as data
110+ if ($ c0 === false ) {
104111 $ data = $ this ->buffer ;
105112 $ this ->buffer = '' ;
106113
107114 $ this ->emit ('data ' , array ($ data ));
108115 return ;
109116 }
110117
111- // ESC found somewhere inbetween, emit everything before ESC as data
112- if ($ esc !== 0 ) {
113- $ data = substr ($ this ->buffer , 0 , $ esc );
114- $ this ->buffer = substr ($ this ->buffer , $ esc );
118+ // C0 found somewhere inbetween, emit everything before C0 as data
119+ if ($ c0 !== 0 ) {
120+ $ data = substr ($ this ->buffer , 0 , $ c0 );
121+ $ this ->buffer = substr ($ this ->buffer , $ c0 );
115122
116123 $ this ->emit ('data ' , array ($ data ));
117124 }
118125
119- // ESC is now at start of buffer
126+ // C0 is now at start of buffer
127+ // check if this is a normal C0 code or an ESC (\x1B = \033)
128+ // normal C0 will be emitted, ESC will be parsed further
129+ if ($ this ->buffer [0 ] !== "\x1B" ) {
130+ $ data = $ this ->buffer [0 ];
131+ $ this ->buffer = (string )substr ($ this ->buffer , 1 );
132+
133+ $ this ->emit ('c0 ' , array ($ data ));
134+ break ;
135+ }
136+
120137 // check following byte to determine type
121138 if (!isset ($ this ->buffer [1 ])) {
122139 // type currently unknown, wait for next data chunk
0 commit comments