aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
531 stars 97 forks source link

Case insensitive Command/CTCP parsing #45

Closed angelsl closed 7 years ago

angelsl commented 8 years ago

RFC 2812 specifies a command to be

command    =  1*letter / 3digit
letter     =  %x41-5A / %x61-7A       ; A-Z / a-z

There is no mention of case sensitivity of commands.

Currently, Command::new and *SubCommand::from_str only accept uppercase commands. IrcServer::handle_ctcp also only accepts uppercase commands.

As far as I know, all IRC servers now accept commands regardless of case, and most clients will respond to CTCP commands regardless of case.

This would be a trivial fix, but we also want to reduce allocations, so ...

Possible solutions

  1. Match on the &strs to_uppercase()ed.

    The problem with this is now you get an additional allocation which will be thrown away immediately (unless it can be optimised away?)

  2. Use eq_ignore_ascii_case

    This disregards Unicode case (although there are no commands that are not purely letters), and will be ugly compared to a simple match.

retep998 commented 8 years ago

IRC is an inherently byte based protocol anyway, so using ascii case insensitive equality is the ideal solution for an IRC library, no need to care about unicode.

aatxe commented 7 years ago

I used solution two. As it turns out, there really wasn't enough code for it to be that much worse. The large portion for Command already used if statements.