diff --git a/src/HtmlQuery.php b/src/HtmlQuery.php
index 612f257..d74db36 100644
--- a/src/HtmlQuery.php
+++ b/src/HtmlQuery.php
@@ -1102,11 +1102,9 @@ protected function validateNodes($nodes)
{
if (empty($nodes)) {
$nodes = [];
- } elseif ($nodes instanceof DOMNode) {
- $nodes = [$nodes];
- }
-
- if (!is_array($nodes) && !($nodes instanceof Traversable)) {
+ } elseif ($nodes instanceof Traversable) {
+ $nodes = iterator_to_array($nodes);
+ } elseif ($nodes instanceof DOMNode || !is_array($nodes)) {
$nodes = [$nodes];
}
diff --git a/tests/HtmlQueryTest.php b/tests/HtmlQueryTest.php
index 894f45e..b581fe8 100644
--- a/tests/HtmlQueryTest.php
+++ b/tests/HtmlQueryTest.php
@@ -89,6 +89,12 @@ public function testValidateNodes()
$validateNodes(array_merge($nodes, $nodes))
);
+ $fruits = $hq->find('.fruit');
+ $this->assertEquals(
+ $fruits->getNodes(),
+ $validateNodes($fruits)
+ );
+
$exception = null;
try {
$validateNodes([1]);