Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use list instead of regex for string split #509

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/floki/selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ defmodule Floki.Selector do
defp do_classes_matches?(nil, _classes), do: false

defp do_classes_matches?(class_attr_value, classes) do
classes -- String.split(class_attr_value, ~r/\s+/) == []
classes -- String.split(class_attr_value, [" ", "\t", "\n"]) == []
end

defp attributes_matches?(_node, []), do: true
Expand Down
4 changes: 2 additions & 2 deletions lib/floki/selector/attribute_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule Floki.Selector.AttributeSelector do
s.attribute
|> get_value(attributes)
# Splits by whitespaces ("a b c" -> ["a", "b", "c"])
|> String.split(~r/\s+/)
|> String.split([" ", "\t", "\n"])
|> Enum.any?(fn v -> String.downcase(v) == selector_value end)
end

Expand Down Expand Up @@ -103,7 +103,7 @@ defmodule Floki.Selector.AttributeSelector do

def match?(attributes, s = %AttributeSelector{match_type: :includes, value: value}) do
get_value(s.attribute, attributes)
|> String.split(~r/\s+/)
|> String.split([" ", "\t", "\n"])
|> Enum.any?(fn v -> v == value end)
end

Expand Down
Loading