Skip to content

Commit fcd9c2d

Browse files
bug #47175 [DowCrawler] Fix locale-sensitivity of whitespace normalization (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DowCrawler] Fix locale-sensitivity of whitespace normalization | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46822 | License | MIT | Doc PR | - Also aligning with https://infra.spec.whatwg.org/#ascii-whitespace Commits ------- a632fe2 [DowCrawler] Fix locale-sensitivity of whitespace normalization
2 parents 0420d3c + a632fe2 commit fcd9c2d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,15 @@ public function text(/* string $default = null, bool $normalizeWhitespace = true
620620
$text = $this->getNode(0)->nodeValue;
621621

622622
if (\func_num_args() <= 1) {
623-
if (trim(preg_replace('/(?:\s{2,}+|[^\S ])/', ' ', $text)) !== $text) {
623+
if (trim(preg_replace("/(?:[ \n\r\t\x0C]{2,}+|[\n\r\t\x0C])/", ' ', $text), " \n\r\t\x0C") !== $text) {
624624
@trigger_error(sprintf('"%s()" will normalize whitespaces by default in Symfony 5.0, set the second "$normalizeWhitespace" argument to false to retrieve the non-normalized version of the text.', __METHOD__), \E_USER_DEPRECATED);
625625
}
626626

627627
return $text;
628628
}
629629

630630
if (\func_num_args() > 1 && func_get_arg(1)) {
631-
return trim(preg_replace('/(?:\s{2,}+|[^\S ])/', ' ', $text));
631+
return trim(preg_replace("/(?:[ \n\r\t\x0C]{2,}+|[\n\r\t\x0C])/", ' ', $text), " \n\r\t\x0C");
632632
}
633633

634634
return $text;

0 commit comments

Comments
 (0)