Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LIBXML_PARSEHUGE #294

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Literal/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct($value, $lang = null, $datatype = null)
public function domParse()
{
$dom = new \DOMDocument();
$dom->loadXML($this->value);
$dom->loadXML($this->value, LIBXML_PARSEHUGE);
return $dom;
}
}
20 changes: 13 additions & 7 deletions lib/Parser/RdfXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,19 @@ public function parse($graph, $data, $format, $baseUri)
$this->initXMLParser();

/* parse */
if (!xml_parse($this->xmlParser, $data, false)) {
$message = xml_error_string(xml_get_error_code($this->xmlParser));
throw new Exception(
'XML error: "' . $message . '"',
xml_get_current_line_number($this->xmlParser),
xml_get_current_column_number($this->xmlParser)
);

$resource = fopen('data://text/plain,' . $data, 'r');

while ($data = fread($resource, 1024 * 1024)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You said you test it on a 150 MB xml, but is it a one line xml or a multiline one? If this is a one line (or that contains lines bigger than 1024 x 1024 characters, does it work fine?

if (!xml_parse($this->xmlParser, $data, feof($resource))) {
$message = xml_error_string(xml_get_error_code($this->xmlParser));

throw new Exception(
sprintf('XML error: "%s"', $message),
xml_get_current_line_number($this->xmlParser),
xml_get_current_column_number($this->xmlParser)
);
}
}

xml_parser_free($this->xmlParser);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sparql/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ protected function newTerm($data)
protected function parseXml($data)
{
$doc = new \DOMDocument();
$doc->loadXML($data);
$doc->loadXML($data, LIBXML_PARSEHUGE);

# Check for valid root node.
if ($doc->hasChildNodes() == false or
Expand Down
7 changes: 7 additions & 0 deletions test/EasyRdf/GraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ public function testParseFile()
$this->assertSame(null, $name->getDatatype());
}

public function testParseLargeFile()
Copy link

@Daniel-KM Daniel-KM Oct 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the tabs on all this function? It prevents Travis check.

Suggested change
public function testParseLargeFile()
public function testParseLargeFile()
{
$graph = new Graph();
$count = $graph->parseFile(fixturePath('stw.rdf'));
$this->assertSame(109340, $count);
}

{
$graph = new Graph();
$count = $graph->parseFile(fixturePath('stw.rdf'));
$this->assertSame(109340, $count);
}

public function testParseFileRelativeUri()
{
$graph = new Graph();
Expand Down
Loading