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

Floki.find/2 doesn't find ids ending with `?` #583

Closed randycoulman closed 3 months ago

randycoulman commented 3 months ago

Description

I originally thought that this might be a bug in PhoenixTest, but it looks it's actually in Floki.

If I have a form field with an id ending in a ? character (e.g. active?), Floki is unable to find the element. If I remove the ?, then all is well.

To Reproduce

(h/t to @germsvel for coming up with a simple example)

Steps to reproduce the behavior:

Expected behavior

I'd expect Floki to be able to find the element.

ypconstante commented 3 months ago

#hello? isn't a valid selector, both Chrome and Firefox raise an error with it

> document.querySelector("#hello?")
VM74:1 Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#hello?' is not a valid selector.

You'll need to use Floki.get_by_id/2 or |> Floki.find("[id='hello?']")

randycoulman commented 3 months ago

Wow, interesting! Thanks for taking a look @ypconstante! I did search for whether that was a valid DOM id, and it seems to be from what I can tell. But if it doesn't work as a selector, that makes things difficult.

I'll close this.