diff --git a/lib/Parser/RdfXml.php b/lib/Parser/RdfXml.php index 108e6151..af411ecf 100644 --- a/lib/Parser/RdfXml.php +++ b/lib/Parser/RdfXml.php @@ -799,13 +799,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,' . urlencode($data), 'r'); + + while ($data = fread($resource, 1024 * 1024)) { + 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); diff --git a/test/EasyRdf/Parser/RdfXmlTest.php b/test/EasyRdf/Parser/RdfXmlTest.php index 9d06f9dd..429d6581 100644 --- a/test/EasyRdf/Parser/RdfXmlTest.php +++ b/test/EasyRdf/Parser/RdfXmlTest.php @@ -178,4 +178,20 @@ public function testIssue157() $this->assertEquals('http://www.example.org/base#foo', $iri); } } + + /** + * Tests faulty behavior of issue https://github.com/sweetyrdf/easyrdf/issues/15 + * + * RDF-XML containing URL-encode special characters is parsed properly + * + * @see https://github.com/sweetyrdf/easyrdf/issues/15 + */ + public function testParseIssue15() + { + $graph = new Graph(); + $this->parser->parse($graph, readFixture('rdfxml/issue15.rdf'), 'rdfxml', null); + $resource = $graph->resource('https://vocabs.acdh.oeaw.ac.at/archeoaisets/clarin-vlo'); + $value = $resource->getLiteral('http://purl.org/dc/terms/created'); + $this->assertEquals('2019-10-07T11:15:48.188959+00:00', (string) $value); + } } diff --git a/test/fixtures/issue15.rdf b/test/fixtures/issue15.rdf new file mode 100644 index 00000000..4eeae21f --- /dev/null +++ b/test/fixtures/issue15.rdf @@ -0,0 +1,6 @@ + + + + 2019-10-07T11:15:48.188959+00:00 + +