summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2004-01-06 12:09:42 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2004-01-06 12:09:42 +0000
commitb817bdb302050195881ce501dd98cacde651494f (patch)
tree4376250981cd62ceed9b1b9503b7a64537fb46ce /includes
parent7cf848279ceec2f8870fe80f4be6343c37528f1e (diff)
downloadbrdo-b817bdb302050195881ce501dd98cacde651494f.tar.gz
brdo-b817bdb302050195881ce501dd98cacde651494f.tar.bz2
- 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. */
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc28
-rw-r--r--includes/xmlrpc.inc5
-rw-r--r--includes/xmlrpcs.inc5
3 files changed, 31 insertions, 7 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 304e753ca..2eae306cb 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -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";
diff --git a/includes/xmlrpc.inc b/includes/xmlrpc.inc
index 0ac5a04a2..9ad7f8ea1 100644
--- a/includes/xmlrpc.inc
+++ b/includes/xmlrpc.inc
@@ -89,8 +89,6 @@ $xmlrpcstr["no_ssl"]="No SSL support compiled in.";
$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 @@ class xmlrpcmsg {
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();
diff --git a/includes/xmlrpcs.inc b/includes/xmlrpcs.inc
index 01d81822e..c98e5dd51 100644
--- a/includes/xmlrpcs.inc
+++ b/includes/xmlrpcs.inc
@@ -208,15 +208,14 @@ class xmlrpc_server {
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']="";