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

Ensure the correctness of ASCII matching in parser #20

Merged
merged 1 commit into from
May 9, 2018
Merged
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
16 changes: 8 additions & 8 deletions lib/saxy/parser/element.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Saxy.Parser.Element do
end

def parse_open_tag(<<charcode, rest::bits>>, cont, original, pos, state)
when is_name_start_char(charcode) do
when is_ascii(charcode) and is_name_start_char(charcode) do
parse_open_tag_name(rest, cont, original, pos, state, 1)
end

Expand All @@ -36,7 +36,7 @@ defmodule Saxy.Parser.Element do
end

def parse_open_tag_name(<<charcode, rest::bits>>, cont, original, pos, state, len)
when is_name_char(charcode) do
when is_ascii(charcode) and is_name_char(charcode) do
parse_open_tag_name(rest, cont, original, pos, state, len + 1)
end

Expand Down Expand Up @@ -97,7 +97,7 @@ defmodule Saxy.Parser.Element do
end

def parse_sattribute(<<charcode, rest::bits>>, cont, original, pos, state, attributes)
when is_name_start_char(charcode) do
when is_ascii(charcode) and is_name_start_char(charcode) do
parse_attribute_name(rest, cont, original, pos, state, attributes, 1)
end

Expand All @@ -119,7 +119,7 @@ defmodule Saxy.Parser.Element do
end

def parse_attribute_name(<<charcode, rest::bits>>, cont, original, pos, state, attributes, len)
when is_name_char(charcode) do
when is_ascii(charcode) and is_name_char(charcode) do
parse_attribute_name(rest, cont, original, pos, state, attributes, len + 1)
end

Expand Down Expand Up @@ -212,7 +212,7 @@ defmodule Saxy.Parser.Element do
end

def parse_att_value_entity_ref(<<charcode, rest::bits>>, cont, original, pos, state, attributes, q, att_name, acc, 0)
when is_name_start_char(charcode) do
when is_ascii(charcode) and is_name_start_char(charcode) do
parse_att_value_entity_ref(rest, cont, original, pos, state, attributes, q, att_name, acc, 1)
end

Expand All @@ -222,7 +222,7 @@ defmodule Saxy.Parser.Element do
end

def parse_att_value_entity_ref(<<charcode, rest::bits>>, cont, original, pos, state, attributes, q, att_name, acc, len)
when is_name_char(charcode) do
when is_ascii(charcode) and is_name_char(charcode) do
parse_att_value_entity_ref(rest, cont, original, pos, state, attributes, q, att_name, acc, len + 1)
end

Expand Down Expand Up @@ -619,7 +619,7 @@ defmodule Saxy.Parser.Element do
end

def parse_close_tag_name(<<charcode, rest::bits>>, cont, original, pos, state, 0)
when is_name_start_char(charcode) do
when is_ascii(charcode) and is_name_start_char(charcode) do
parse_close_tag_name(rest, cont, original, pos, state, 1)
end

Expand Down Expand Up @@ -668,7 +668,7 @@ defmodule Saxy.Parser.Element do
end

def parse_close_tag_name(<<charcode, rest::bits>>, cont, original, pos, state, len)
when is_name_char(charcode) do
when is_ascii(charcode) and is_name_char(charcode) do
parse_close_tag_name(rest, cont, original, pos, state, len + 1)
end

Expand Down
11 changes: 11 additions & 0 deletions test/saxy/parser/element_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ defmodule Saxy.Parser.ElementTest do
assert [{:end_element, "foo"} | events] = events
assert [{:end_document, {}} | events] = events
assert events == []

buffer = "<fóo></fóo>"

assert {:ok, state} = parse_element(buffer, make_cont(), buffer, 0, make_state())

events = Enum.reverse(state.user_state)

assert [{:start_element, {"fóo", []}} | events] = events
assert [{:end_element, "fóo"} | events] = events
assert [{:end_document, {}} | events] = events
assert events == []
end

test "parses element with nested children" do
Expand Down