Skip to content

Commit

Permalink
Parse escaped colons in class names correctly (#458)
Browse files Browse the repository at this point in the history
* Parse escaped colons in classnames correctly

* Run mix format
  • Loading branch information
viniciusmuller authored May 19, 2023
1 parent 0a08a8e commit 46e8cc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/floki_selector_lexer.xrl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Rules.
{SYMBOL} : {token, {TokenChars, TokenLine}}.
#{IDENTIFIER} : {token, {hash, TokenLine, tail(TokenChars)}}.
\.{IDENTIFIER} : {token, {class, TokenLine, tail(TokenChars)}}.
\.{IDENTIFIER}\\:{IDENTIFIER} : {token, {class, TokenLine, tail(TokenChars)}}.
\:{NOT}\( : {token, {pseudo_not, TokenLine}}.
\:{IDENTIFIER} : {token, {pseudo, TokenLine, tail(TokenChars)}}.
\({INT}\) : {token, {pseudo_class_int, TokenLine, list_to_integer(remove_wrapper(TokenChars))}}.
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 @@ -22,6 +22,14 @@ defmodule Floki.Selector.ParserTest do
end
end

test "escaped colons in class names" do
tokens = tokenize("a.xs\\:red-500")

assert Parser.parse(tokens) == [
%Selector{type: "a", classes: ["xs\\:red-500"], pseudo_classes: []}
]
end

test "multiple selectors" do
tokens = tokenize("ol, ul")

Expand Down

0 comments on commit 46e8cc8

Please sign in to comment.