Skip to content

Commit

Permalink
Fix XML parsing failures due to non-breaking spaces
Browse files Browse the repository at this point in the history
Using ` ` for non-breaking spaces is not supported in the XML
serialization of HTML5, so replace with the character code equivalent so that
SimpleXML can properly parse the page.
  • Loading branch information
gapple committed Nov 24, 2013
1 parent 5676a79 commit 87fecff
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/DrupalReleaseDate/DrupalIssueCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,19 @@ public function getXmlDocument(\Guzzle\Http\Message\Response $response) {
libxml_use_internal_errors(true);
$document = $response->xml();
}
catch (\RuntimeException $e) {
catch (\Guzzle\Common\Exception\RuntimeException $e) {
libxml_clear_errors();

// Drupal.org may return invalid XML due to unescaped ampersands
// Drupal.org may return invalid XML due to unescaped ampersands and
// non-breaking spaces (which aren't valid in XHTML serialization of
// HTML5).
$page = (string) $response->getBody();

$page = str_replace(' & ', ' & ', $page);
$replace = array(
' & ' => ' & ',
' ' => ' ',
);
$page = str_replace(array_keys($replace), array_values($replace), $page);

$document = new \SimpleXMLElement($page);
}
Expand Down

0 comments on commit 87fecff

Please sign in to comment.