Skip to content

Commit 249687d

Browse files
committed
bug #26433 [DomCrawler] extract(): fix a bug when the attribute list is empty (dunglas)
This PR was merged into the 2.7 branch. Discussion ---------- [DomCrawler] extract(): fix a bug when the attribute list is empty | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | n/a Commits ------- 028c9f2366 [DomCrawler] extract(): fix a bug when the attribute list is empty
2 parents d5112f7 + ef75d97 commit 249687d

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)