Skip to content

Combining div with ID containing '?' and phx-update="ignore" throughs Floki error #3144

Closed
@nathanmalishev

Description

Environment

  • Phoenix LiveView version (mix deps): Introduced 20.0.7 -> 20.0.8

Actual behavior

Any div in combination with an ID containing '?' along with 'phx-update=ignore' will throw a Floki error, only when running tests

Throws error -> <div id="test?param=1" phx-update="ignore"></div>
Does not throw error -> <div id="test?param=1"></div>

Example repo -> https://github.com/nathanmalishev/dom_id_phx_ignore_test/blob/d1d0243851d141527d93ec2155bd185b919ad239/lib/dom_id_phx_ignore_web/live/article_live/index.html.heex#L10

 ** (FunctionClauseError) no function clause matching in Floki.Selector.Parser.do_parse/2

          The following arguments were given to Floki.Selector.Parser.do_parse/2:

              # 1
              [{:equal, 1}, {:identifier, 1, ~c"1"}]

              # 2
              %Floki.Selector{id: "test", type: "param", classes: [], attributes: [], namespace: nil, pseudo_classes: [], combinator: nil}

          Attempted function clauses (showing 10 out of 21):

              defp do_parse([], selector)
              defp do_parse([{:close_parentesis, _} | t], selector)
              defp do_parse([{:comma, _} | t], selector)
              defp do_parse([{:identifier, _, namespace}, {:namespace_pipe, _} | t], selector)
              defp do_parse([{:identifier, _, type} | t], selector)
              defp do_parse([{~c"*", _} | t], selector)
              defp do_parse([{:hash, _, id} | t], selector)
              defp do_parse([{:class, _, class} | t], selector)
              defp do_parse([{~c"[", _} | t], selector)
              defp do_parse([{:pseudo_not, _} | t], selector)
              ...
              (11 clauses not shown)

          stacktrace:
            (floki 0.35.4) lib/floki/selector/parser.ex:40: Floki.Selector.Parser.do_parse/2
            (floki 0.35.4) lib/floki/selector/parser.ex:36: Floki.Selector.Parser.do_parse_all/2
            (floki 0.35.4) lib/floki/finder.ex:21: Floki.Finder.find/2
            (phoenix_live_view 0.20.11) lib/phoenix_live_view/test/dom.ex:572: Phoenix.LiveViewTest.DOM.by_id/2
            (phoenix_live_view 0.20.11) lib/phoenix_live_view/test/dom.ex:447: Phoenix.LiveViewTest.DOM.apply_phx_update/4
            (floki 0.35.4) lib/floki/traversal.ex:6: anonymous fn/3 in Floki.Traversal.traverse_and_update/2
            (floki 0.35.4) lib/floki/traversal.ex:18: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:23: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:37: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:18: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:37: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:18: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:23: Floki.Traversal.traverse_and_update/3
            (floki 0.35.4) lib/floki/traversal.ex:6: Floki.Traversal.traverse_and_update/2
            (phoenix_live_view 0.20.11) lib/phoenix_live_view/test/dom.ex:305: Phoenix.LiveViewTest.DOM.patch_id/4
            (phoenix_live_view 0.20.11) lib/phoenix_live_view/test/client_proxy.ex:656: Phoenix.LiveViewTest.ClientProxy.patch_view/4
            (phoenix_live_view 0.20.11) lib/phoenix_live_view/test/client_proxy.ex:156: Phoenix.LiveViewTest.ClientProxy.init/1
            (stdlib 5.2) gen_server.erl:980: :gen_server.init_it/2
            (stdlib 5.2) gen_server.erl:935: :gen_server.init_it/6
            (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Expected behavior

Believe this shouldn't occur as there's no HTML restrictions around '?' in div ids?

I was using this for ease of reference in testing to just assert that the src links were on the page as they should be.

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions