Commit b817bdb3 authored by Steven Wittens's avatar Steven Wittens

- Improved XML encoding fix. There is now a function drupal_xml_parser_create():

/**
 * Wrapper around xml_parser_create() which extracts the encoding from the XML
 * data first and sets the output encoding to UTF-8. This function should be
 * used instead of xml_parser_create(), because PHP's XML parser doesn't check
 * the input encoding itself.
 *
 * This is also where unsupported encodings should be converted.
 * Callers should take this into account: $data might have been changed after
 * the call.
 *
 * @param $data The XML data which will be parsed later.
 */
parent 7cf84827
......@@ -835,6 +835,34 @@ function drupal_page_footer() {
module_invoke_all("exit");
}
/**
* Wrapper around xml_parser_create() which extracts the encoding from the XML
* data first and sets the output encoding to UTF-8. This function should be
* used instead of xml_parser_create(), because PHP's XML parser doesn't check
* the input encoding itself.
*
* This is also where unsupported encodings should be converted.
* Callers should take this into account: $data might have been changed after
* the call.
*
* @param $data The XML data which will be parsed later.
*/
function drupal_xml_parser_create(&$data) {
$encoding = 'utf-8';
if (ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) {
$encoding = $match[1];
}
/*
* Note: unsupported encodings will need to be converted here into UTF-8,
* and $encoding set to 'utf-8'.
*/
$xml_parser = xml_parser_create($encoding);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'utf-8');
return $xml_parser;
}
include_once "includes/theme.inc";
include_once "includes/pager.inc";
include_once "includes/menu.inc";
......
......@@ -89,8 +89,6 @@
$xmlrpcerr["curl_fail"]=8;
$xmlrpcstr["curl_fail"]="CURL error";
$xmlrpc_defencoding="UTF-8";
$xmlrpcName="XML-RPC for PHP";
$xmlrpcVersion="1.02";
......@@ -622,10 +620,9 @@ function parseResponseFile($fp) {
function parseResponse($data="") {
global $_xh,$xmlrpcerr,$xmlrpcstr;
global $xmlrpc_defencoding;
$parser = xml_parser_create($xmlrpc_defencoding);
$parser = drupal_xml_parser_create($data);
$_xh[$parser]=array();
......
......@@ -208,15 +208,14 @@ function verifySignature($in, $sig) {
function parseRequest($data="") {
global $_xh;
global $xmlrpcerr, $xmlrpcstr, $xmlrpcerrxml, $xmlrpc_defencoding,
$_xmlrpcs_dmap;
global $xmlrpcerr, $xmlrpcstr, $xmlrpcerrxml, $_xmlrpcs_dmap;
if ($data=="") {
$data=$GLOBALS["HTTP_RAW_POST_DATA"];
}
$parser = xml_parser_create($xmlrpc_defencoding);
$parser = drupal_xml_parser_create($data);
$_xh[$parser]=array();
$_xh[$parser]['st']="";
......
......@@ -325,17 +325,10 @@ function import_refresh($feed) {
return t("failed to parse RSS feed '%site': suspicious input data.", array("%site" => $feed["title"]));
}
// extract the XML file's encoding (the XML parser in PHP4 doesn't do this by itself):
$encoding = 'utf-8';
if (ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) {
$encoding = $match[1];
}
// parse the data:
$xml_parser = xml_parser_create($encoding);
$xml_parser = drupal_xml_parser_create($data);
xml_set_element_handler($xml_parser, "import_element_start", "import_element_end");
xml_set_character_data_handler($xml_parser, "import_element_data");
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "utf-8");
if (!xml_parse($xml_parser, $data, 1)) {
return t("failed to parse RSS feed '%site': %error at line %line.", array("%site" => $feed["title"], "%error" => xml_error_string(xml_get_error_code($xml_parser)), "%line" => xml_get_current_line_number($xml_parser)));
......
......@@ -325,17 +325,10 @@ function import_refresh($feed) {
return t("failed to parse RSS feed '%site': suspicious input data.", array("%site" => $feed["title"]));
}
// extract the XML file's encoding (the XML parser in PHP4 doesn't do this by itself):
$encoding = 'utf-8';
if (ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) {
$encoding = $match[1];
}
// parse the data:
$xml_parser = xml_parser_create($encoding);
$xml_parser = drupal_xml_parser_create($data);
xml_set_element_handler($xml_parser, "import_element_start", "import_element_end");
xml_set_character_data_handler($xml_parser, "import_element_data");
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "utf-8");
if (!xml_parse($xml_parser, $data, 1)) {
return t("failed to parse RSS feed '%site': %error at line %line.", array("%site" => $feed["title"], "%error" => xml_error_string(xml_get_error_code($xml_parser)), "%line" => xml_get_current_line_number($xml_parser)));
......
......@@ -325,17 +325,10 @@ function import_refresh($feed) {
return t("failed to parse RSS feed '%site': suspicious input data.", array("%site" => $feed["title"]));
}
// extract the XML file's encoding (the XML parser in PHP4 doesn't do this by itself):
$encoding = 'utf-8';
if (ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) {
$encoding = $match[1];
}
// parse the data:
$xml_parser = xml_parser_create($encoding);
$xml_parser = drupal_xml_parser_create($data);
xml_set_element_handler($xml_parser, "import_element_start", "import_element_end");
xml_set_character_data_handler($xml_parser, "import_element_data");
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "utf-8");
if (!xml_parse($xml_parser, $data, 1)) {
return t("failed to parse RSS feed '%site': %error at line %line.", array("%site" => $feed["title"], "%error" => xml_error_string(xml_get_error_code($xml_parser)), "%line" => xml_get_current_line_number($xml_parser)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment