Try to refactoring old libxml support (but now it's not supported officially)

This commit is contained in:
Frederic Guillot 2013-06-02 13:25:27 -04:00
parent 0a91f85f65
commit 80f44c5311
2 changed files with 9 additions and 17 deletions

View File

@ -38,6 +38,7 @@ Authors
Requirements
------------
- Recent version of libxml2 >= 2.7.x (version 2.6.32 on Debian Lenny are not supported anymore)
- PHP >= 5.3.7
- PHP XML extensions (SimpleXML, DOM...)
- PHP Sqlite extension

View File

@ -115,16 +115,13 @@ class Filter
// Workaround for old libxml2 (Debian Lenny)
if (LIBXML_DOTTED_VERSION === '2.6.32') {
do {
$unique = md5(uniqid());
} while(strpos($data, $unique) !== false);
$entity_alpha = array('&', '<', '>');
$entity_num = array('&', '<', '>');
$token = array($unique.'a', $unique.'l', $unique.'r');
$data = str_replace($entity_alpha, $token, $data);
$data = str_replace($entity_num, $token, $data);
$data = html_entity_decode($data, ENT_NOQUOTES|ENT_XHTML, 'UTF-8');
$data = str_replace($token, $entity_alpha, $data);
$entities = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES|ENT_XHTML, 'UTF-8');
unset($entities['&']);
unset($entities['>']);
unset($entities['<']);
$data = str_replace(array_values($entities), array_keys($entities), $data);
}
// Convert bad formatted documents to XML
@ -144,13 +141,7 @@ class Filter
xml_set_element_handler($parser, 'startTag', 'endTag');
xml_set_character_data_handler($parser, 'dataTag');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
if (! xml_parse($parser, $this->input, true)) {
//var_dump($this->input);
die(xml_get_current_line_number($parser).'|'.xml_error_string(xml_get_error_code($parser)));
}
xml_parse($parser, $this->input, true); // We ignore parsing error (for old libxml)
xml_parser_free($parser);
return $this->data;