Skip to content

Commit

Permalink
Support HTML ids which contain periods (#359)
Browse files Browse the repository at this point in the history
Closes #352


Co-authored-by: Hugo Hache <hugo.hache@spaceable.org>
  • Loading branch information
Hugo-Hache and Hugo Hache committed Oct 6, 2021
1 parent ec056fb commit 5240128
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/floki/selector/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Floki.Selector.Parser do
end

defp do_parse([{:hash, _, id} | t], selector) do
do_parse(t, %{selector | id: to_string(id)})
do_parse(t, %{selector | id: to_string(id) |> String.replace("\\.", ".")})
end

defp do_parse([{:class, _, class} | t], selector) do
Expand Down
2 changes: 1 addition & 1 deletion src/floki_selector_lexer.xrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Definitions.

IDENTIFIER = [-A-Za-z0-9_]+
IDENTIFIER = [-A-Za-z0-9_]+(\\\.[-A-Za-z0-9_]+)*
QUOTED = (\"[^"]*\"|\'[^']*\')
PARENTESIS = \([^)]*\)
INT = [0-9]+
Expand Down
8 changes: 8 additions & 0 deletions test/floki/selector/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ defmodule Floki.Selector.ParserTest do
assert Parser.parse(tokens) == [%Selector{type: "img", id: "logo"}]
end

test "id containing periods" do
tokens = tokenize("#my\\.example\\.com-port-filters.big.blue")

assert Parser.parse(tokens) == [
%Selector{id: "my.example.com-port-filters", classes: ["blue", "big"]}
]
end

test "class with attributes" do
tokens =
tokenize("""
Expand Down

0 comments on commit 5240128

Please sign in to comment.