Skip to content

Commit 3a74903

Browse files
Merge branch '4.4'
* 4.4: Re-allow to use "tagged" in service definitions [HttpFoundation] Allow to not pass a parameter to Request::isMethodSafe() Add missing lock connection string in FrameworkExtension [DomCrawler] normalizeWhitespace should be true by default [DoctrineBridge] Auto-validation must work if no regex are passed Allows URL DSN in Lock and Cache
2 parents c5b3e5c + 36bbcab commit 3a74903

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Crawler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ public function nodeName()
571571
/**
572572
* Returns the text of the first node of the list.
573573
*
574-
* Pass true as the 2nd argument to normalize whitespaces.
574+
* Pass true as the second argument to normalize whitespaces.
575575
*
576576
* @param string|null $default When not null: the value to return when the current node is empty
577577
* @param bool $normalizeWhitespace Whether whitespaces should be trimmed and normalized to single spaces
@@ -580,7 +580,7 @@ public function nodeName()
580580
*
581581
* @throws \InvalidArgumentException When current node is empty
582582
*/
583-
public function text(string $default = null, bool $normalizeWhitespace = false)
583+
public function text(string $default = null, bool $normalizeWhitespace = true)
584584
{
585585
if (!$this->nodes) {
586586
if (null !== $default) {
@@ -592,7 +592,7 @@ public function text(string $default = null, bool $normalizeWhitespace = false)
592592

593593
$text = $this->getNode(0)->nodeValue;
594594

595-
if (\func_num_args() > 1 && func_get_arg(1)) {
595+
if ($normalizeWhitespace) {
596596
return trim(preg_replace('/(?:\s{2,}+|[^\S ])/', ' ', $text));
597597
}
598598

Tests/AbstractCrawlerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ public function testNormalizeWhiteSpace()
258258
$crawler = $this->createTestCrawler()->filterXPath('//p');
259259
$this->assertSame('Elsa <3', $crawler->text(null, true), '->text(null, true) returns the text with normalized whitespace');
260260
$this->assertNotSame('Elsa <3', $crawler->text(null, false));
261+
}
262+
263+
/**
264+
* @group legacy
265+
*/
266+
public function testLegacyNormalizeWhiteSpace()
267+
{
268+
$crawler = $this->createTestCrawler()->filterXPath('//p');
261269
$this->assertNotSame('Elsa <3', $crawler->text());
262270
}
263271

0 commit comments

Comments
 (0)