Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Apr 21, 2019
1 parent 293f890 commit b9b445a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.1] - 2019-04-21
### Fixed
- `parseFragment` was returning a fragment containing only the first element

## 0.1.0 - 2019-04-21
First version

[0.1.1]: https://github.com/oscarotero/html-parser/compare/v0.1.0...v0.1.1
6 changes: 6 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public static function parseFragment(string $html): DOMDocumentFragment

$body = $document->getElementsByTagName('body')->item(0);

$nodes = [];

foreach ($body->childNodes as $node) {
$nodes[] = $node;
}

foreach ($nodes as $node) {
$fragment->appendChild($node);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/HtmlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class HtmlParserTest extends TestCase
{
public function testHtmlFragment()
{
$html = '<img src="http://example.com/image.png?123456" alt="Image">';
$html = '<img src="http://example.com/image.png?123456" alt="Image"><span>Hello world</span>';

$fragment = Parser::parseFragment($html);

$this->assertInstanceOf(DOMDocumentFragment::class, $fragment);
$this->assertCount(1, $fragment->childNodes);
$this->assertCount(2, $fragment->childNodes);
$this->assertSame('img', $fragment->childNodes->item(0)->tagName);
$this->assertSame($html, Parser::stringify($fragment));
}
Expand Down

0 comments on commit b9b445a

Please sign in to comment.