File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,11 +50,12 @@ private function parseMessage($message)
5050 $ key = Response::FIELD_COMMAND_OUTPUT ;
5151 $ value = $ line ;
5252 } else {
53- $ pos = strpos ($ line , ': ' );
53+ $ pos = strpos ($ line , ': ' );
5454 if ($ pos === false ) {
5555 throw new \UnexpectedValueException ('Parse error, no colon in line " ' . $ line . '" found ' );
5656 }
57- $ value = substr ($ line , $ pos + 2 );
57+
58+ $ value = (string )substr ($ line , $ pos + (isset ($ line [$ pos + 1 ]) && $ line [$ pos + 1 ] === ' ' ? 2 : 1 ));
5859 $ key = substr ($ line , 0 , $ pos );
5960 }
6061
Original file line number Diff line number Diff line change @@ -124,14 +124,33 @@ public function testParsingInvalidResponseFails()
124124 $ parser ->push ("invalid response \r\n\r\n" );
125125 }
126126
127- /**
128- * @expectedException UnexpectedValueException
129- */
130- public function testParsingInvalidResponseNoSpaceAfterColonFails ()
127+ public function testParsingMissingSpaceWithValue ()
131128 {
132129 $ parser = new Parser ();
133130 $ this ->assertEquals (array (), $ parser ->push ("Asterisk Call Manager/1.3 \r\n" ));
134131
135- $ parser ->push ("Response:NoSpace \r\n\r\n" );
132+ $ ret = $ parser ->push ("Response:NoSpace \r\n\r\n" );
133+ $ this ->assertCount (1 , $ ret );
134+
135+ $ first = reset ($ ret );
136+ /* @var $first Clue\React\Ami\Protocol\Response */
137+
138+ $ this ->assertInstanceOf ('Clue\React\Ami\Protocol\Response ' , $ first );
139+ $ this ->assertEquals ('NoSpace ' , $ first ->getFieldValue ('Response ' ));
140+ }
141+
142+ public function testParsingMissingSpaceEmptyValue ()
143+ {
144+ $ parser = new Parser ();
145+ $ this ->assertEquals (array (), $ parser ->push ("Asterisk Call Manager/1.3 \r\n" ));
146+
147+ $ ret = $ parser ->push ("Response: \r\n\r\n" );
148+ $ this ->assertCount (1 , $ ret );
149+
150+ $ first = reset ($ ret );
151+ /* @var $first Clue\React\Ami\Protocol\Response */
152+
153+ $ this ->assertInstanceOf ('Clue\React\Ami\Protocol\Response ' , $ first );
154+ $ this ->assertEquals ('' , $ first ->getFieldValue ('Response ' ));
136155 }
137156}
You can’t perform that action at this time.
0 commit comments