gsnedders
04-01-2007, 12:40 AM
Under the following code, basic_parser::entity_ref() is never called, despite there being a PUBLIC/SYSTEM entity.
<?php
class basic_parser
{
function parse($data, $encoding)
{
$this->xml = xml_parser_create_ns($encoding);
xml_set_object($this->xml, $this);
xml_set_external_entity_ref_handler($this->xml, 'entity_ref');
var_dump(xml_parse($this->xml, $data, true), xml_get_error_code($this->xml), xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml), xml_get_current_column_number($this->xml));
}
function entity_ref($parser, $open_entity_names, $base, $system_id, $public_id)
{
var_dump($parser, $open_entity_names, $base, $system_id, $public_id);
}
}
$parser = new basic_parser;
$data = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE rdf:RDF [
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1 for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
%HTMLlat1;
]>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
>
<channel>
<title>This That</title>
</channel>
</rdf:RDF>';
$parser->parse($data, 'ISO-8859-1');
?>
xml_parse() also manages to return 0, giving the script the following output:
int(0)
int(26)
string(23) "Undeclared entity error"
int(7)
int(3)
Line 7 column 3 is the LF after the end of the DOCTYPE.
<?php
class basic_parser
{
function parse($data, $encoding)
{
$this->xml = xml_parser_create_ns($encoding);
xml_set_object($this->xml, $this);
xml_set_external_entity_ref_handler($this->xml, 'entity_ref');
var_dump(xml_parse($this->xml, $data, true), xml_get_error_code($this->xml), xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml), xml_get_current_column_number($this->xml));
}
function entity_ref($parser, $open_entity_names, $base, $system_id, $public_id)
{
var_dump($parser, $open_entity_names, $base, $system_id, $public_id);
}
}
$parser = new basic_parser;
$data = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE rdf:RDF [
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1 for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
%HTMLlat1;
]>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
>
<channel>
<title>This That</title>
</channel>
</rdf:RDF>';
$parser->parse($data, 'ISO-8859-1');
?>
xml_parse() also manages to return 0, giving the script the following output:
int(0)
int(26)
string(23) "Undeclared entity error"
int(7)
int(3)
Line 7 column 3 is the LF after the end of the DOCTYPE.