diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2015-01-14 22:23:45 +0100 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2015-01-14 22:23:45 +0100 |
commit | 9fb4c103ada01379008f7331cd29dcd56dfe7c9b (patch) | |
tree | 35d0c97f5e94033c60c86f01eaf3f36d54d79dd8 /src/net/java/sip | |
parent | c2d1ec097c4b42aa25f7c92c4c1ebc9ee96d054b (diff) | |
download | jitsi-9fb4c103ada01379008f7331cd29dcd56dfe7c9b.zip jitsi-9fb4c103ada01379008f7331cd29dcd56dfe7c9b.tar.gz jitsi-9fb4c103ada01379008f7331cd29dcd56dfe7c9b.tar.bz2 |
IRC: check nick according to nick pattern in RFC 1459.
Diffstat (limited to 'src/net/java/sip')
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java | 38 | ||||
-rw-r--r-- | src/net/java/sip/communicator/plugin/irccommands/command/Nick.java | 2 |
2 files changed, 11 insertions, 29 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java b/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java index e03fb91..1c2393c 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java @@ -6,7 +6,7 @@ */ package net.java.sip.communicator.impl.protocol.irc; -import java.util.*; +import java.util.regex.*; import net.java.sip.communicator.util.*; @@ -37,24 +37,10 @@ public class IdentityManager .getLogger(IdentityManager.class); /** - * Reserved symbols. These symbols have special meaning and cannot be used - * to start nick names. - * - * FIXME remove this reserved symbol list, after checkNick(...) was - * improved. + * Pattern of a valid nick. */ - private static final Set<Character> RESERVED; - - /** - * Initialize RESERVED symbols set. - */ - static - { - final HashSet<Character> reserved = new HashSet<Character>(); - reserved.add('#'); - reserved.add('&'); - RESERVED = Collections.unmodifiableSet(reserved); - } + public static final Pattern NICK_PATTERN = Pattern + .compile("[A-Za-z][A-Za-z0-9\\-\\[\\]\\\\`\\^\\{\\}]*"); /** * The IRCApi instance. @@ -198,21 +184,17 @@ public class IdentityManager public static String checkNick(final String nick, final Integer isupportNickLen) { - if (nick == null) + if (nick == null || nick.isEmpty()) { - throw new IllegalArgumentException( - "a nick name must be provided"); + throw new IllegalArgumentException("a nick name must be provided"); } - if (RESERVED.contains(nick.charAt(0))) + if (!NICK_PATTERN.matcher(nick).matches()) { throw new IllegalArgumentException( - "the nick name must not start with '#' or '&' " - + "since these are reserved for IRC's channels"); + "nick name contains invalid characters: only letters, " + + "digits and -, \\, [, ], `, ^, {, } are allowed"); } - // FIXME Improve nick verification corresponding to RFC1459, section - // 2.3.1 - if (isupportNickLen != null - && nick.length() > isupportNickLen.intValue()) + if (isupportNickLen != null && nick.length() > isupportNickLen) { throw new IllegalArgumentException("the nick name must not be " + "longer than " + isupportNickLen.intValue() + " characters " diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java b/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java index f3fe3b6..599a638 100644 --- a/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java +++ b/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java @@ -66,7 +66,7 @@ public class Nick implements Command { newNick = part.substring(0, indexOfSep); } - if (newNick.length() > 0) + if (!newNick.isEmpty()) { this.connection.getIdentityManager().setNick(newNick); } |