Skip to content

Commit

Permalink
Parsing fails when XML declaration is missing and a standard PI is pr…
Browse files Browse the repository at this point in the history
…esent (#134)
  • Loading branch information
lucacorti authored Oct 22, 2024
1 parent 3cc45a3 commit adb66d2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
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>

0 comments on commit adb66d2

Please sign in to comment.