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

FunctionClauseError for :not pseudo selector and equal attribute value check #110

Closed Eiji7 closed 7 years ago

Eiji7 commented 7 years ago

Example code:

iex> html = "<select id='my_select'><option value=''></option><option value='1'>1</option></select>"
"<select id='my_select'><option value=''></option><option value='1'>1</option></select>"
iex> Floki.find(html, "#my_select > option:not([value=''])")  
** (FunctionClauseError) no function clause matching in Floki.SelectorParser.do_parse/2
    (floki) lib/floki/selector_parser.ex:31: Floki.SelectorParser.do_parse([equal: 1], %Floki.Selector{attributes: [%Floki.AttributeSelector{attribute: nil, match_type: nil, value: nil}], classes: [], combinator: nil, id: nil, namespace: nil, pseudo_classes: [], type: "value"})
    (floki) lib/floki/selector_parser.ex:171: Floki.SelectorParser.do_parse_pseudo_not/3
    (floki) lib/floki/selector_parser.ex:54: Floki.SelectorParser.do_parse/2
    (floki) lib/floki/selector_parser.ex:145: Floki.SelectorParser.consume_combinator/2
    (floki) lib/floki/selector_parser.ex:88: Floki.SelectorParser.do_parse/2
    (floki) lib/floki/selector_parser.ex:27: Floki.SelectorParser.do_parse_all/2
    (floki) lib/floki/finder.ex:24: Floki.Finder.find/2
    (floki) lib/floki.ex:146: Floki.find/2

I tested on latest 0.17.0 release and master branch - both returns same exception to console. Important: this example works in version: 0.16.0! ping @philss

philss commented 7 years ago

@Eiji7 Thank you for the report. I'm looking into it.

jjcarstens commented 7 years ago

Tested this with #114 and should be golden once that is merged:

iex> html = "<select id='my_select'><option value=''></option><option value='1'>1</option></select>"
iex> Floki.find(html, "#my_select > option:not([value=''])")
[{"option", [{"value", "1"}], ["1"]}]