Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #32 from Renegade334/devel-numeric-params
Browse files Browse the repository at this point in the history
Add 'iterable' key to numeric reply params array
  • Loading branch information
elazar committed May 26, 2015
2 parents d7dd26a + d8e6aa4 commit dc55f4c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function parse($message)
}

// Clean up and store the processed parameters
$params = array_merge(array('all' => $params[0]), array_filter($params));
$params = array_merge(array('all' => $params[0]), array_filter($params, 'strlen'));
$params = $this->removeIntegerKeys($params);
$parsed['params'] = $params;
} elseif (ctype_digit($command)) {
Expand All @@ -430,8 +430,14 @@ public function parse($message)
}
$params = explode(' ', $head);
$params[] = $tail;
if ($params = array_filter($params)) {
if ($params = array_filter($params, 'strlen')) {
$parsed['params'] = array_combine(range(1, count($params)), $params);
if (strlen($tail)) {
$parsed['params']['iterable'] = array_slice($params, 0, -1);
$parsed['params']['tail'] = $tail;
} else {
$parsed['params']['iterable'] = array_values($params);
}
$parsed['params']['all'] = $all;
}
}
Expand Down
43 changes: 37 additions & 6 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2642,8 +2642,10 @@ public function dataProviderTestParse()
'servername' => 'server.name',
'command' => '372',
'params' => array(
1 => "Who left a null byte in here?",
'all' => "Who left a null byte in here?",
1 => 'Who left a null byte in here?',
'iterable' => array(),
'tail' => 'Who left a null byte in here?',
'all' => 'Who left a null byte in here?',
),
'code' => 'RPL_MOTD',
'target' => 'BotNick',
Expand All @@ -2658,8 +2660,10 @@ public function dataProviderTestParse()
'servername' => 'server.name',
'command' => '372',
'params' => array(
1 => "Who left a carriage return in here?",
'all' => "Who left a carriage return in here?",
1 => 'Who left a carriage return in here?',
'iterable' => array(),
'tail' => 'Who left a carriage return in here?',
'all' => 'Who left a carriage return in here?',
),
'code' => 'RPL_MOTD',
'target' => 'BotNick',
Expand All @@ -2674,8 +2678,10 @@ public function dataProviderTestParse()
'servername' => 'server.name',
'command' => '372',
'params' => array(
1 => "Who left a line feed in here?",
'all' => "Who left a line feed in here?",
1 => 'Who left a line feed in here?',
'iterable' => array(),
'tail' => 'Who left a line feed in here?',
'all' => 'Who left a line feed in here?',
),
'code' => 'RPL_MOTD',
'target' => 'BotNick',
Expand All @@ -2696,6 +2702,13 @@ public function dataProviderTestParse()
3 => 'DOQRSZaghilopswz',
4 => 'CFILMPQbcefgijklmnopqrstvz',
5 => 'bkloveqjfI',
'iterable' => array(
'pratchett.freenode.net',
'ircd-seven-1.1.3',
'DOQRSZaghilopswz',
'CFILMPQbcefgijklmnopqrstvz',
'bkloveqjfI',
),
'all' => 'pratchett.freenode.net ircd-seven-1.1.3 DOQRSZaghilopswz CFILMPQbcefgijklmnopqrstvz bkloveqjfI',
),
'code' => '004',
Expand All @@ -2713,6 +2726,8 @@ public function dataProviderTestParse()
'params' => array(
1 => '#laravel',
2 => 'http://laravel.com',
'iterable' => array('#laravel'),
'tail' => 'http://laravel.com',
'all' => '#laravel :http://laravel.com',
),
'message' => ":services. 328 Phergie3 #laravel :http://laravel.com\r\n",
Expand Down Expand Up @@ -2836,6 +2851,22 @@ public function dataProviderTestParse()
'targets' => array('target'),
),
),

// Check that the string '0' is not filtered out from a params list
array(
"USER myident 0 * :Ronnie Reagan\r\n",
array(
'command' => 'USER',
'params' => array(
'all' => 'myident 0 * :Ronnie Reagan',
'username' => 'myident',
'hostname' => '0',
'servername' => '*',
'realname' => 'Ronnie Reagan',
),
'targets' => array('myident'),
),
),
);

foreach ($data as $key => $value) {
Expand Down

0 comments on commit dc55f4c

Please sign in to comment.