Skip to content

Commit

Permalink
Bugfix: setText() should convert special chars. Closes #34.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasinger committed Jun 28, 2019
1 parent b1d0aad commit 6c3e391
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Tests/HtmlPageCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,14 @@ public function testText()
$this->assertEquals('jklojklo', $c->text());
}

public function testSetText()
{
$c = HtmlPageCrawler::create('<div>&quot;</div>');
$this->assertEquals('"', $c->text());
$c->setText('&');
$this->assertEquals('&', $c->text());
}

public function testMagicGet()
{
// $crawler->length should give us the number of nodes in the crawler
Expand Down
1 change: 1 addition & 0 deletions src/HtmlPageCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ public function getCombinedText()
*/
public function setText($text)
{
$text = htmlspecialchars($text);
foreach ($this as $node) {
/** @var \DOMNode $node */
$node->nodeValue = $text;
Expand Down

0 comments on commit 6c3e391

Please sign in to comment.