Skip to content

Commit ef75d97

Browse files
committed
[DomCrawler] extract(): fix a bug when the attribute list is empty
1 parent 5ca496b commit ef75d97

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public function extract($attributes)
605605
}
606606
}
607607

608-
$data[] = $count > 1 ? $elements : $elements[0];
608+
$data[] = 1 === $count ? $elements[0] : $elements;
609609
}
610610

611611
return $data;

Tests/CrawlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public function testExtract()
369369

370370
$this->assertEquals(array('One', 'Two', 'Three'), $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list');
371371
$this->assertEquals(array(array('One', 'first'), array('Two', ''), array('Three', '')), $crawler->extract(array('_text', 'class')), '->extract() returns an array of extracted data from the node list');
372+
$this->assertEquals(array(array(), array(), array()), $crawler->extract(array()), '->extract() returns empty arrays if the attribute list is empty');
372373

373374
$this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty');
374375
}

0 commit comments

Comments
 (0)