diff options
author | Paul Schoenfelder <paulschoenfelder@gmail.com> | 2017-04-20 16:55:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-20 16:55:16 -0500 |
commit | 81c5fc697d800300e265d74dd1496801318c03e7 (patch) | |
tree | 07ee2dd86f7c2e28b91e38e718aa851a0f2f8583 | |
parent | Merge pull request #63 from shymega/fix-lint-errors (diff) | |
parent | Add test for uncloaked user (diff) |
Merge pull request #64 from shymega/fix-irc-regex
Fix IRC regex handling of slashes in host
-rw-r--r-- | lib/exirc/utils.ex | 2 | ||||
-rw-r--r-- | test/utils_test.exs | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/exirc/utils.ex b/lib/exirc/utils.ex index b2a79cd..2573cc3 100644 --- a/lib/exirc/utils.ex +++ b/lib/exirc/utils.ex @@ -25,7 +25,7 @@ defmodule ExIrc.Utils do end end - @prefix_pattern ~r/^(?<nick>[^!]+)(?:!(?:(?<user>[^@ ]+)@)?(?:(?<host>[\w.:-]+)))?$/ + @prefix_pattern ~r/^(?<nick>[^!\s]+)(?:!(?:(?<user>[^@\s]+)@)?(?:(?<host>[\S]+)))?$/ defp parse_from(from, msg) do from_str = IO.iodata_to_binary(from) parts = Regex.run(@prefix_pattern, from_str, capture: :all_but_first) diff --git a/test/utils_test.exs b/test/utils_test.exs index 33f6907..dce38c0 100644 --- a/test/utils_test.exs +++ b/test/utils_test.exs @@ -25,6 +25,34 @@ defmodule ExIrc.UtilsTest do assert expected == result end + test "Parse cloaked user" do + message = ':foo!foo@unaffiliated/foo PRIVMSG #bar Hiya.' + expected = %IrcMessage{ + nick: "foo", + cmd: "PRIVMSG", + host: "unaffiliated/foo", + ctcp: false, + user: "foo", + args: ["#bar", "Hiya."] + } + result = Utils.parse(message) + assert expected == result + end + + test "Parse uncloaked (normal) user" do + message = ':foo!foo@80.21.56.43 PRIVMSG #bar Hiya.' + expected = %IrcMessage{ + nick: "foo", + cmd: "PRIVMSG", + host: "80.21.56.43", + ctcp: false, + user: "foo", + args: ["#bar", "Hiya."] + } + result = Utils.parse(message) + assert expected == result + end + test "Parse INVITE message" do message = ':pschoenf INVITE testuser #awesomechan' assert %IrcMessage{ |