Skip to content

Commit

Permalink
Fixed an issue when parsing an empty string.
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes committed May 22, 2016
1 parent 0dfbab6 commit 42cce74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## CHANGELOG

### 0.0.3
- Fixed an issue when parsing an empty string.

### 0.0.2
- Added a way to parse content from a URL.

Expand Down
4 changes: 4 additions & 0 deletions src/DOMParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public function parse($dom)
$this->init();
$dom = new \simple_html_dom((string) $dom);

if (null === $dom->root) {
return array();
}

// We filter the exclusion first to be able to use a global selector.
$this->filterExcluded($dom);

Expand Down
7 changes: 7 additions & 0 deletions tests/DOMParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,11 @@ public function testParseURLRaisesAnExceptionIfUnreachableURL()
$parser = new DOMParser();
$parser->parseURL('https://nothing.algolia.biz');
}

public function testHandlesEmptyStringGracefully()
{
$parser = new DOMParser();
$records = $parser->parse('');
$this->assertEquals(array(), $records);
}
}

0 comments on commit 42cce74

Please sign in to comment.