Skip to content

Commit 95146f9

Browse files
committed
Allowed arguments in Request constructor to be spread across multiple lines;
The same fix has also been applied in Response's _receive() method to prevent cut offs at some edge case scenarios.
1 parent 6fb97a0 commit 95146f9

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

RELEASE-1.0.0b3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Bug fixes on edge cases, and some API changes
22

33
* Persistent connections are now properly supported. Added a new Registry class to facilitate this.
44
* The second and third argument of Request::__construct() have been swapped.
5-
* At Request::__construct(), a backslash can now be escaped in an argument value.
5+
* At Request::__construct(), a backslash can now be escaped in an argument value, and arguments can be spread across multiple lines.
66
* Client::getStreamResponses() and Client::setStreamResponses() are now Client::isStreamingResponses() and Client::setStreamingResponses(), respectively.
77
* Query now uses things statically, allowing extensions in the process.
88
* ResponseCollection::__invoke() now seeks instead of getting.

src/PEAR2/Net/RouterOS/Request.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ protected function parseArgumentString($string)
327327
$name = null;
328328
while ($string = substr($string, strlen($token))) {
329329
if (null === $name) {
330-
if (preg_match('/^\s+([^\s=]+)/sm', $string, $matches)) {
330+
if (preg_match('/^\s+([^\s=]+)/sS', $string, $matches)) {
331331
$token = $matches[0];
332332
$name = $matches[1];
333333
} else {
@@ -336,13 +336,13 @@ protected function parseArgumentString($string)
336336
41000
337337
);
338338
}
339-
} elseif (preg_match('/^\s/sm', $string, $matches)) {
339+
} elseif (preg_match('/^\s/s', $string, $matches)) {
340340
//Empty argument
341341
$token = '';
342342
$this->setArgument($name);
343343
$name = null;
344344
} elseif (
345-
preg_match('/^="(([^\\\"]|\\\"|\\\\)*)"/sm', $string, $matches)
345+
preg_match('/^="(([^\\\"]|\\\"|\\\\)*)"/sS', $string, $matches)
346346
) {
347347
$token = $matches[0];
348348
$this->setArgument(
@@ -352,7 +352,7 @@ protected function parseArgumentString($string)
352352
)
353353
);
354354
$name = null;
355-
} elseif (preg_match('/^=(\S+)/sm', $string, $matches)) {
355+
} elseif (preg_match('/^=(\S+)/sS', $string, $matches)) {
356356
$token = $matches[0];
357357
$this->setArgument($name, $matches[1]);
358358
$name = null;

src/PEAR2/Net/RouterOS/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ private function _receive(Communicator $com, $asStream = false)
176176
for ($word = $com->getNextWord(); '' !== $word;
177177
$word = $com->getNextWord()
178178
) {
179-
if (preg_match('/^=([^=]+)=(.*)$/sm', $word, $matches)) {
179+
if (preg_match('/^=([^=]+)=(.*)$/sS', $word, $matches)) {
180180
$this->setArgument($matches[1], $matches[2]);
181-
} elseif (preg_match('/^\.tag=(.*)$/sm', $word, $matches)) {
181+
} elseif (preg_match('/^\.tag=(.*)$/sS', $word, $matches)) {
182182
$this->setTag($matches[1]);
183183
} else {
184184
$this->unrecognizedWords[] = $word;

tests/RequestHandlingTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ public function testCommandTranslationWithArguments()
153153
'/ping address=192.168.0.1 count=2' => '/ping',
154154
'/ping address="192.168.0.1" count=2' => '/ping',
155155
'/ping address=192.168.0.1 count="2"' => '/ping',
156-
'/ping address="192.168.0.1" count="2"' => '/ping'
156+
'/ping address="192.168.0.1" count="2"' => '/ping',
157+
'/ping address=192.168.0.1
158+
count="2"' => '/ping',
159+
'/ping address="192.168.0.1"
160+
count="2"' => '/ping'
157161
);
158162
foreach ($commands as $command => $expected) {
159163
$request = new Request($command);
@@ -327,6 +331,12 @@ public function testCommandArgumentParsing()
327331
=> array('address' => '192.168.0.1', 'count' => '2'),
328332
'/ping address="192.168.0.1" count="2"'
329333
=> array('address' => '192.168.0.1', 'count' => '2'),
334+
'/ping address=192.168.0.1
335+
count="2"'
336+
=> array('address' => '192.168.0.1', 'count' => '2'),
337+
'/ping address="192.168.0.1"
338+
count="2"'
339+
=> array('address' => '192.168.0.1', 'count' => '2'),
330340
);
331341
foreach ($commands as $command => $expected) {
332342
$request = new Request($command);

0 commit comments

Comments
 (0)