Skip to content

Commit

Permalink
bug #26433 [DomCrawler] extract(): fix a bug when the attribute list …
Browse files Browse the repository at this point in the history
…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
-------

028c9f2 [DomCrawler] extract(): fix a bug when the attribute list is empty
  • Loading branch information
fabpot committed Mar 13, 2018
2 parents ed63ab6 + 028c9f2 commit ffd088a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/Crawler.php
Expand Up @@ -605,7 +605,7 @@ public function extract($attributes)
}
}

$data[] = $count > 1 ? $elements : $elements[0];
$data[] = 1 === $count ? $elements[0] : $elements;
}

return $data;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Expand Up @@ -369,6 +369,7 @@ public function testExtract()

$this->assertEquals(array('One', 'Two', 'Three'), $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list');
$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');
$this->assertEquals(array(array(), array(), array()), $crawler->extract(array()), '->extract() returns empty arrays if the attribute list is empty');

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

0 comments on commit ffd088a

Please sign in to comment.