Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floki crashes for Floki.attribute on a node list with only text nodes #280

Closed
ckruse opened this issue Jun 13, 2020 · 0 comments
Closed
Labels

Comments

@ckruse
Copy link
Contributor

ckruse commented Jun 13, 2020

Description

Given this fragment:

<p>test</p>

Floki crashes when calling Floki.attribute on Floki.children of the root node:

Floki.attribute(children, "class")
** (FunctionClauseError) no function clause matching in anonymous fn/2 in Floki.attribute_values/2    
    
    The following arguments were given to anonymous fn/2 in Floki.attribute_values/2:
    
        # 1
        "test"
    
        # 2
        []
    
    lib/floki.ex:540: anonymous fn/2 in Floki.attribute_values/2
    (elixir 1.10.3) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/floki.ex:537: Floki.attribute_values/2

To Reproduce

Steps to reproduce the behavior:

  • Using Floki v0.26.0

  • Using Elixir v1.10.3

  • Using Erlang/OTP 23 [erts-11.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

  • With this code:

     "<p>test</p>"
    |> Floki.parse_fragment!()
    |> List.first
    |> Floki.children()
    |> Floki.attribute("class")

Expected behavior

Floki should return an empty list.

@ckruse ckruse added the Bug label Jun 13, 2020
@philss philss closed this as completed in 4579dd2 Jun 18, 2020
philss added a commit that referenced this issue Jun 18, 2020
fix #280: child nodes might be text nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant