philss / floki

Floki is a simple HTML parser that enables search for nodes using CSS selectors.
https://hex.pm/packages/floki
MIT License
2.07k stars 156 forks source link

error with Floki.find/2 #138

Closed danturn closed 7 years ago

danturn commented 7 years ago

Hi,

I have been using Floki for a bit without issues but had a crash today that i can't repro

the stack trace is:

[error] GenServer #PID<0.804.0> terminating ** (Protocol.UndefinedError) protocol Enumerable not implemented for "xml" (elixir) lib/enum.ex:1: Enumerable.impl_for!/1 (elixir) lib/enum.ex:116: Enumerable.reduce/3 (elixir) lib/enum.ex:278: Enum.any?/2 (elixir) lib/enum.ex:2718: Enum.do_all?/2 (floki) lib/floki/selector.ex:63: Floki.Selector.match?/3 (floki) lib/floki/finder.ex:73: Floki.Finder.get_matches/3 (elixir) lib/enum.ex:966: Enum.flat_map_list/2 (floki) lib/floki/finder.ex:49: Floki.Finder.find_selectors/2 (floki) lib/floki.ex:149: Floki.find/2

And unfortunately i dont have the input! i can't work out from the code how this could happen, my filter is: nested_scopes = Floki.find(text, "[itemscope] [itemscope]") so selecting itemscope attributes inside other elements that have itemscope attributes which works fine everywhere i have seen so far.

Just wondering if you might have some idea about how i could repro?

Dan

philss commented 7 years ago

Hi Dan!

I think this is something related to a parsing of XML. I will try to reproduce with some inputs. Can you tell me the Elixir version you are using?

danturn commented 7 years ago

That was a quick response! Erlang/OTP 19 [erts-8.0.5] [source-99c6fd1] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false] Elixir (1.4.5) Let me know if i can help at all or if it's just user error on my part ;p

philss commented 7 years ago

Hi @danturn. Sorry for the delay. This PR will fix the issue: https://github.com/philss/floki/pull/139 Please take a look.

danturn commented 7 years ago

Hey, Sorry for the delay! Awesome work, thanks for that

I will see if I can get the client to test again but that looks like exactly what my issue was

thanks!

Dan