From 028c9f23667ee02180a49b099bbf74f876cf0114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 6 Mar 2018 23:27:05 +0100 Subject: [PATCH] [DomCrawler] extract(): fix a bug when the attribute list is empty --- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index cccea633dd..a49bb3930a 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -605,7 +605,7 @@ class Crawler extends \SplObjectStorage } } - $data[] = $count > 1 ? $elements : $elements[0]; + $data[] = 1 === $count ? $elements[0] : $elements; } return $data; diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index 3ba9247618..74acfdf8c6 100644 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -369,6 +369,7 @@ EOF $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'); }