philss / floki

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

Floki.find/2 fails on HTML that consists entirely of a comment #175

Closed QuinnWilton closed 6 years ago

QuinnWilton commented 6 years ago

When attempting to upgrade from Floki 0.7.1 to 0.20.0 I noticed this change.

Under 0.7.1:

iex(1)> Floki.find("<!-- test -->", "test")
[]

Under 0.20.0:

iex(1)> Floki.find("<!-- test -->", "test")
** (FunctionClauseError) no function clause matching in Floki.HTMLTree.build/1    

    The following arguments were given to Floki.HTMLTree.build/1:

        # 1
        {:comment, " test "}

    Attempted function clauses (showing 2 out of 2):

        def build({tag, attrs, children})
        def build(html_tuples) when is_list(html_tuples)

    (floki) lib/floki/html_tree.ex:14: Floki.HTMLTree.build/1
    (floki) lib/floki/finder.ex:47: Floki.Finder.find_selectors/2
    (floki) lib/floki.ex:127: Floki.find/2
philss commented 6 years ago

@ShaneWilton thank you for the report! This is a bug introduced when we added the Floki.HTMLTree abstraction. I will investigate more of this one later.

philss commented 6 years ago

@ShaneWilton fixed in version 0.20.1. Please check. Thanks!

QuinnWilton commented 6 years ago

Thanks Philip!

I'll verify this is fixed when I'm back in my office tomorrow.

On Thu, Apr 5, 2018, 19:30 Philip Sampaio notifications@github.com wrote:

Closed #175 https://github.com/philss/floki/issues/175.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/philss/floki/issues/175#event-1560063752, or mute the thread https://github.com/notifications/unsubscribe-auth/AARcfbhQ9NleLzD2HXUZnQiEpuda3y47ks5tltNHgaJpZM4SylSJ .

QuinnWilton commented 6 years ago

@philss I just ran through a battery of tests in my app with 0.20.1, and everything seems to be working great. Thanks for looking into this and fixing the issue!