Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into hotf…
Browse files Browse the repository at this point in the history
…ix/validator-db-abstractdb-tableIdentifier
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ public static function importString($string)
$libxml_errflag = libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
$dom = new DOMDocument;
$status = $dom->loadXML($string);
$status = $dom->loadXML(trim($string));
libxml_disable_entity_loader(false);
libxml_use_internal_errors($libxml_errflag);

if (!$status) {
// Build error message
$error = libxml_get_last_error();
if ($error && $error->message) {
$error->message = trim($error->message);
$errormsg = "DOMDocument cannot parse XML: {$error->message}";
} else {
$errormsg = "DOMDocument cannot parse XML: Please check the XML document's validity";
Expand All @@ -298,7 +299,7 @@ public static function importString($string)
$reader = new Feed\Atom($dom, $type);
} else {
throw new Exception\RuntimeException('The URI used does not point to a '
. 'valid Atom, RSS or RDF feed that Zend_Feed_Reader can parse.');
. 'valid Atom, RSS or RDF feed that Zend\Feed\Reader can parse.');
}
return $reader;
}
Expand Down Expand Up @@ -340,13 +341,14 @@ public static function findFeedLinks($uri)
$libxml_errflag = libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
$dom = new DOMDocument;
$status = $dom->loadHTML($responseHtml);
$status = $dom->loadHTML(trim($responseHtml));
libxml_disable_entity_loader(false);
libxml_use_internal_errors($libxml_errflag);
if (!$status) {
// Build error message
$error = libxml_get_last_error();
if ($error && $error->message) {
$error->message = trim($error->message);
$errormsg = "DOMDocument cannot parse HTML: {$error->message}";
} else {
$errormsg = "DOMDocument cannot parse HTML: Please check the XML document's validity";
Expand Down
7 changes: 7 additions & 0 deletions test/Reader/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public function tearDown()
Reader\Reader::reset();
}

public function testStringImportTrimsContentToAllowSlightlyInvalidXml()
{
$feed = Reader\Reader::importString(
' ' . file_get_contents($this->_feedSamplePath.'/Reader/rss20.xml')
);
}

public function testDetectsFeedIsRss20()
{
$feed = Reader\Reader::importString(
Expand Down

0 comments on commit 543ff20

Please sign in to comment.