Skip to content

Commit

Permalink
ignore declarations when detecting duplicate ids
Browse files Browse the repository at this point in the history
Closes #3594.
  • Loading branch information
SteffenDE committed Dec 21, 2024
1 parent 6c6a915 commit a00ba4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/phoenix_live_view/test/dom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ defmodule Phoenix.LiveViewTest.DOM do
detect_duplicate_ids(rest, ids)
end

# ignore declarations
defp detect_duplicate_ids({:pi, _type, _attrs}, seen_ids), do: seen_ids

defp detect_duplicate_ids({_tag_name, _attrs, children} = node, ids) do
case Floki.attribute(node, "id") do
[id] ->
Expand Down
20 changes: 20 additions & 0 deletions test/phoenix_live_view/test/dom_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,24 @@ defmodule Phoenix.LiveViewTest.DOMTest do
%{s: "bar", streams: []}
end
end

describe "parse" do
test "detects duplicate ids" do
assert_raise RuntimeError, fn ->
DOM.parse("""
<div id="foo">
<div id="foo"></div>
</div>
""")
end
end

test "handles declarations (issue #3594)" do
assert DOM.parse("""
<div id="foo">
<?xml version="1.0" standalone="yes"?>
</div>
""")
end
end
end

0 comments on commit a00ba4f

Please sign in to comment.