Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Net_IRC::checkNick($nick) + test

git-svn-id: http://svn.php.net/repository/pear/packages/Net_IRC/trunk@81683 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit fa63133fcc9b416aaefa82e64f2b603ba81e6875 1 parent 0b68a91
@tvvcox tvvcox authored
Showing with 37 additions and 0 deletions.
  1. +15 −0 IRC.php
  2. +22 −0 tests/checkNick.php
View
15 IRC.php
@@ -470,6 +470,21 @@ function getExtra($label = null)
return $this->extra;
}
+ /**
+ * Checks if a nick is valid or not (RFC 2812 section 2.3.1)
+ *
+ * @param string $nick The nick to check
+ * @return bool The result of the validation
+ */
+ function checkNick($nick)
+ {
+ $special = preg_quote("[]\'_^{|}");
+ if (preg_match("/^[a-zA-Z$special][a-zA-Z0-9$special]{0,8}\$/", $nick)) {
+ return true;
+ }
+ return false;
+ }
+
}
/**
View
22 tests/checkNick.php
@@ -0,0 +1,22 @@
+<?php
+require '../IRC.php';
+$nicks = array(
+ 'aaa' => true,
+ 'a1' => true,
+ 'a1a' => true,
+ '{1}' => true,
+ '[a]' => true,
+ 'a' => true,
+ '[' => true,
+ '1' => false,
+ '1a' => false,
+ 'aaaaaaaaaa' => false,
+ '?' => false,
+ 'a?' => false
+);
+foreach ($nicks as $nick => $res) {
+ if ($res != Net_IRC::checkNick($nick)) {
+ print "The test for nick '$nick' failed\n";
+ }
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.