diff --git a/lib/irc/mode.ml b/lib/irc/mode.ml index 1dd05fe..71a80b3 100644 --- a/lib/irc/mode.ml +++ b/lib/irc/mode.ml @@ -145,7 +145,7 @@ module Parse = struct in loop `none init 0 - let take = function + let take_string = function | [] -> fail "expected argument" | x :: xs -> x, xs @@ -154,6 +154,15 @@ module Parse = struct | x :: xs -> try int_of_string x, xs with Invalid_argument _ -> fail "invalid integer" + let is_valid_key = function + | "" | "*" -> false + | _ -> true + + let take_key = function + | [] -> fail "expected argument" + | x :: xs when is_valid_key x -> x, xs + | _ -> fail "invalid key" + type user_modes = Set.change let user_modes str = @@ -190,12 +199,12 @@ module Parse = struct args, modes | `k -> (* type B *) - let key, args = take args in + let key, args = take_key args in let chan_key = Some (`set key) in args, { modes with chan_key } | (`o | `v) as priv -> (* type B *) - let nick, args = take args in + let nick, args = take_string args in let chan_privs = (`add, priv, nick) :: modes.chan_privs in args, { modes with chan_privs } | `l -> @@ -218,7 +227,7 @@ module Parse = struct args, modes | `k -> (* type B *) - let _key, args = take args in + let _key, args = take_string args in let chan_key = Some `unset in args, { modes with chan_key } | `l -> @@ -227,7 +236,7 @@ module Parse = struct args, { modes with chan_limit } | (`o | `v) as priv -> (* type B *) - let nick, args = take args in + let nick, args = take_string args in let chan_privs = (`rem, priv, nick) :: modes.chan_privs in args, { modes with chan_privs } | #chan_d as m ->