diff --git a/src/Parser.php b/src/Parser.php index 43ac315..4bd8de5 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -231,7 +231,7 @@ public function __construct() 'SQUIT' => "/^(?:(?P$middle)(?P$trailing))$/", 'JOIN' => "/^(?:(?P$middle|$trailing)(?P$trailing)?)$/", 'PART' => "/^(?:(?P$middle|$trailing)(?P$trailing)?)$/", - 'MODE' => "/^(?:(?P$middle)(?P$middle|$trailing)(?P$trailing)?)$/", + 'MODE' => "/^(?:(?P$middle)(?P$middle|$trailing)(?P$trailing)?)$/", 'TOPIC' => "/^(?:(?P$middle|$trailing)(?P$trailing)?)$/", 'NAMES' => "/^(?:(?P$trailing))$/", 'LIST' => "/^(?:(?:(?P$trailing)|$middle)?(?P$trailing)?)$/", @@ -349,20 +349,31 @@ public function parse($message) case 'MODE': if (preg_match('/^' . $this->channel . '$/', $params['target'])) { $params['channel'] = $params['target']; - if (strpos($params['mode'], 'l') !== false) { - $params['limit'] = $params['param']; - } elseif (strpos($params['mode'], 'b') !== false - && !empty($params['param'])) { - $params['banmask'] = $params['param']; - } elseif (strpos($params['mode'], 'k') !== false) { - $params['key'] = $params['param']; - } elseif (isset($params['param'])) { - $params['user'] = $params['param']; + + /* Assign the value of $params['params'] to a named parameter if + * only one channel mode is being set. + * This functionality is DEPRECATED, and will not occur if more than one + * channel mode is being set. Use $params['params'] instead. */ + if (strlen($params['mode']) == 2 && isset($params['params'])) { + switch ($params['mode']{1}) { + case 'l': + $params['limit'] = $params['params']; + break; + case 'b': + $params['banmask'] = $params['params']; + break; + case 'k': + $params['key'] = $params['params']; + break; + default: + $params['user'] = $params['params']; + break; + } } } else { $params['user'] = $params['target']; } - unset($params['target'], $params['param']); + unset($params['target']); break; // Handle CTCP messages case 'PRIVMSG': diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 81e6427..3546e99 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -456,6 +456,7 @@ public function dataProviderTestParse() 'params' => array( 'channel' => '#Finnish', 'mode' => '+o', + 'params' => 'Kilroy', 'user' => 'Kilroy', 'all' => '#Finnish +o :Kilroy', ), @@ -470,6 +471,7 @@ public function dataProviderTestParse() 'params' => array( 'channel' => '#Finnish', 'mode' => '+v', + 'params' => 'Wiz', 'user' => 'Wiz', 'all' => '#Finnish +v :Wiz', ), @@ -477,6 +479,34 @@ public function dataProviderTestParse() ), ), + array( + "MODE #Finnish +ov :Kilroy Wiz\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'channel' => '#Finnish', + 'mode' => '+ov', + 'params' => 'Kilroy Wiz', + 'all' => '#Finnish +ov :Kilroy Wiz', + ), + 'targets' => array('#Finnish'), + ), + ), + + array( + "MODE #Finnish +mvv-v :Kilroy Wiz Angel\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'channel' => '#Finnish', + 'mode' => '+mvv-v', + 'params' => 'Kilroy Wiz Angel', + 'all' => '#Finnish +mvv-v :Kilroy Wiz Angel', + ), + 'targets' => array('#Finnish'), + ), + ), + array( "MODE #Fins :-s\r\n", array( @@ -497,6 +527,7 @@ public function dataProviderTestParse() 'params' => array( 'channel' => '#42', 'mode' => '+k', + 'params' => 'oulu', 'key' => 'oulu', 'all' => '#42 +k :oulu', ), @@ -504,6 +535,20 @@ public function dataProviderTestParse() ), ), + array( + "MODE #42 +ks :oulu\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'channel' => '#42', + 'mode' => '+ks', + 'params' => 'oulu', + 'all' => '#42 +ks :oulu', + ), + 'targets' => array('#42'), + ), + ), + array( "MODE #eu-opers +l :10\r\n", array( @@ -511,6 +556,7 @@ public function dataProviderTestParse() 'params' => array( 'channel' => '#eu-opers', 'mode' => '+l', + 'params' => '10', 'limit' => '10', 'all' => '#eu-opers +l :10', ), @@ -518,6 +564,20 @@ public function dataProviderTestParse() ), ), + array( + "MODE #eu-opers +lL :10 #eu-opers-overflow\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'channel' => '#eu-opers', + 'mode' => '+lL', + 'params' => '10 #eu-opers-overflow', + 'all' => '#eu-opers +lL :10 #eu-opers-overflow', + ), + 'targets' => array('#eu-opers'), + ), + ), + array( "MODE &oulu :+b\r\n", array( @@ -538,6 +598,7 @@ public function dataProviderTestParse() 'params' => array( 'channel' => '&oulu', 'mode' => '+b', + 'params' => '*!*@*', 'banmask' => '*!*@*', 'all' => '&oulu +b :*!*@*', ), @@ -552,6 +613,7 @@ public function dataProviderTestParse() 'params' => array( 'channel' => '&oulu', 'mode' => '+b', + 'params' => '*!*@*.edu', 'banmask' => '*!*@*.edu', 'all' => '&oulu +b :*!*@*.edu', ), @@ -559,6 +621,20 @@ public function dataProviderTestParse() ), ), + array( + "MODE &oulu +b-b :*!*@*.edu *!*@*.ac.uk\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'channel' => '&oulu', + 'mode' => '+b-b', + 'params' => '*!*@*.edu *!*@*.ac.uk', + 'all' => '&oulu +b-b :*!*@*.edu *!*@*.ac.uk', + ), + 'targets' => array('&oulu'), + ), + ), + array( "MODE Wiz :-w\r\n", array( @@ -600,6 +676,34 @@ public function dataProviderTestParse() ), ), + array( + "MODE Kilroy +s :+CcQq\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'user' => 'Kilroy', + 'mode' => '+s', + 'params' => '+CcQq', + 'all' => 'Kilroy +s :+CcQq', + ), + 'targets' => array('Kilroy'), + ), + ), + + array( + "MODE Angel +ws :+CcQq\r\n", + array( + 'command' => 'MODE', + 'params' => array( + 'user' => 'Angel', + 'mode' => '+ws', + 'params' => '+CcQq', + 'all' => 'Angel +ws :+CcQq', + ), + 'targets' => array('Angel'), + ), + ), + // TOPIC (RFC 1459 Section 4.2.4) array( ":Wiz TOPIC #test :New topic\r\n",