Floki.find doesn't support escaped colons in class names
Description
Floki doesn't support selectors with escaped colons in them, probably it's mixing them up with pseudo selectors
To Reproduce
Steps to reproduce the behavior:
- Using Floki v0.33.1
- Using Elixir v1.13.3
- Using Erlang OTP v24
- With this code:
> Floki.find(document, "a.xs\\:red-500")
[]
Expected behavior
> Floki.find(document, "a.xs\\:red-500")
[{"a", [{"class", "xs\\:red-500"}], ["I'm a link with a funny selector"]}]
The current workaround is to use a[class="xs:red-500"]
I tried adding a escaped colon to this in a way that it doesn't conflict with pseudo-selectors but with no success so far https://github.com/philss/floki/blob/master/src/floki_selector_lexer.xrl#L3
Hi @fakenickels :wave:
I don't know yet how to solve on the lexer/parser level, but there is a way that works today: you can create a Floki.Selector by hand.
html = """
<!doctype html>
<html><head><title>foo</title></head>
<body>
<h1>Hello world</h1>
<div class="container">
<a class="xs:red-500" href="https://example.com">My link</a>
</div>
</body>
</html>
"""
doc = Floki.parse_document!(html)
selector = %Floki.Selector{type: "a", classes: ["xs:red-500"]}
Floki.find(doc, selector)
#=> [{"a", [{"class", "xs:red-500"}, {"href", "https://example.com"}], ["My link"]}]
This is not ideal, but at least solve the problem for now. I will try to check this next week.
hey @fakenickels, would you mind to test the change introduced in #458?