diff --git a/lib/floki/finder.ex b/lib/floki/finder.ex index 4eabeab3..d5e5bbd8 100644 --- a/lib/floki/finder.ex +++ b/lib/floki/finder.ex @@ -47,7 +47,7 @@ defmodule Floki.Finder do stack = Enum.map(selectors, fn s -> {s, node_ids} end) traverse_html_tree(stack, tree, []) - |> Enum.reverse() + |> Enum.sort_by(& &1.node_id) |> Enum.uniq() end diff --git a/test/floki_test.exs b/test/floki_test.exs index 94cfdbfe..8bde64bb 100644 --- a/test/floki_test.exs +++ b/test/floki_test.exs @@ -917,15 +917,24 @@ defmodule FlokiTest do # Floki.find/2 - Selector with descendant combinator test "get elements descending the parent" do + doc = + document!( + html_body(""" +