From a20520b7bee6953bfd5d0250492231ef0fbeb19a Mon Sep 17 00:00:00 2001 From: Eduardo Gurgel Date: Sun, 22 Feb 2015 20:34:13 +1300 Subject: [PATCH] Fix filter_by_prefix malformed case The filter must have the prefix presence, not the other way around --- lib/poxa/channel.ex | 3 +++ lib/poxa/channels_handler.ex | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/poxa/channel.ex b/lib/poxa/channel.ex index b7df146..93bf4b9 100644 --- a/lib/poxa/channel.ex +++ b/lib/poxa/channel.ex @@ -48,9 +48,12 @@ defmodule Poxa.Channel do false iex> Poxa.Channel.matches?("foo-bar", "") false + iex> Poxa.Channel.matches?("foo-bar", nil) + false iex> Poxa.Channel.matches?("foo-bar", "foo-bartman") false """ + def matches?(_, nil), do: false def matches?(_, ""), do: false def matches?(channel, prefix) do base = byte_size(prefix) diff --git a/lib/poxa/channels_handler.ex b/lib/poxa/channels_handler.ex index 964eda7..3889ba8 100644 --- a/lib/poxa/channels_handler.ex +++ b/lib/poxa/channels_handler.ex @@ -43,7 +43,7 @@ defmodule Poxa.ChannelsHandler do defp malformed_request_all_channels?(attributes, filter) do if Enum.all?(attributes, fn s -> Enum.member?(@valid_attributes, s) end) do if Enum.member?(attributes, "user_count") do - filter == nil or !Channel.matches?("presence-", filter) + !Channel.matches?(filter, "presence-") else false end