Skip to content

Commit

Permalink
Return spaces when normalizeWhitespace is false
Browse files Browse the repository at this point in the history
Even if there's no innerText besides whitespace, return the spaces when
normalizeWhitespace is set to false.
  • Loading branch information
otsch committed Jan 11, 2023
1 parent 83918eb commit f8b1d53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ public function innerText(/* bool $normalizeWhitespace = true */): string
}
}

if (!$normalizeWhitespace) {
foreach ($this->getNode(0)->childNodes as $childNode) {
if (\XML_TEXT_NODE === $childNode->nodeType) {
return $childNode->nodeValue;
}
}
}

return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ public function provideInnerTextExamples()
'//*[@id="complex-elements"]/*[@class="four"]',
'Child text',
'',
'',
' ',
],
[
'//*[@id="complex-elements"]/*[@class="five"]',
'Child text Another child',
'',
'',
' ',
],
];
}
Expand Down

0 comments on commit f8b1d53

Please sign in to comment.