From b817bdb302050195881ce501dd98cacde651494f Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Tue, 6 Jan 2004 12:09:42 +0000 Subject: - 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. */ --- modules/aggregator/aggregator.module | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'modules/aggregator/aggregator.module') diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index aed065eaf..eccd80ad0 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -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))); -- cgit v1.2.3