philss/floki

Support HTML ids which contain periods

nathanl opened this issue ยท 3 comments

Feature goal

HTML ids which contain periods are legal, but Floki does not appear to support this. Periods would need to be escaped somehow in a selector so that they're not interpreted as classes.

For instance, to find <form id="my.example.com-port-filters" class="foo">, we could use Floki.find(~s{form#my\\.example\\.com-port-filters.foo}).

This selector works in the browser console using JavaScript's document.querySelector/1.

Turns out there's a workaround.

This came up in the context of using LiveViewTest.element/3. @chrismccord pointed out that the attribute syntax could work, which it does. And it also works here: Floki.find(html, ~s{form[id="my.example.com-port-filters"]}).

@nathanl I will investigate how we can escape the period. If you want to give it a try, I think we need to add a new rule for scaping in the lexer: https://github.com/philss/floki/blob/master/src/floki_selector_lexer.xrl
and then we need to parse it properly here: https://github.com/philss/floki/blob/master/lib/floki/selector/parser.ex

๐Ÿ‘ ๐Ÿ‘ ๐Ÿ˜„