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

Parsing fails when XML declaration is missing and a standard PI is present #134

Merged
merged 2 commits into from
Oct 22, 2024
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
3 changes: 3 additions & 0 deletions lib/saxy/parser/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ defmodule Saxy.Parser.Builder do

defp prolog(<<buffer::bits>>, more?, original, pos, state) do
lookahead(buffer, @streaming) do
"<?xml-" <> _rest ->
prolog_misc(buffer, more?, original, pos, state, [])

"<?xml" <> rest ->
xml_decl(rest, more?, original, pos + 5, state)

Expand Down
5 changes: 4 additions & 1 deletion test/saxy/partial_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ defmodule Saxy.PartialTest do
doctest Saxy.Partial

@fixtures [
"food.xml",
"no-xml-decl.xml",
"no-xml-decl-with-std-pi.xml",
"no-xml-decl-with-custom-pi.xml",
"foo.xml",
"food.xml",
"complex.xml",
"illustrator.svg",
Expand Down
5 changes: 4 additions & 1 deletion test/saxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ defmodule SaxyTest do
doctest Saxy

@fixtures [
"food.xml",
"no-xml-decl.xml",
"no-xml-decl-with-std-pi.xml",
"no-xml-decl-with-custom-pi.xml",
"foo.xml",
"food.xml",
"complex.xml",
"illustrator.svg",
Expand Down
2 changes: 2 additions & 0 deletions test/support/fixture/no-xml-decl-with-custom-pi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?target ptr="self"?>
<foo bar="value"></foo>
2 changes: 2 additions & 0 deletions test/support/fixture/no-xml-decl-with-std-pi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
<foo bar="value"></foo>
1 change: 1 addition & 0 deletions test/support/fixture/no-xml-decl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<foo bar="value"></foo>
Loading