Patch check_stream-wrapperdata_for_encoding for SimpleXML related Bug #51903
Patch version 2010-05-26 13:02 UTC
Return to Bug #51903 |
Download this patch
Patch Revisions:
Developer: mike@php.net
Index: ext/libxml/libxml.c
===================================================================
--- ext/libxml/libxml.c (revision 299769)
+++ ext/libxml/libxml.c (working copy)
@@ -370,6 +370,36 @@
return(NULL);
}
+ /* Check if there's been an external transport protocol with an encoding information */
+ if (enc == XML_CHAR_ENCODING_NONE) {
+ php_stream *s = (php_stream *) context;
+
+ if (s->wrapperdata && Z_TYPE_P(s->wrapperdata) == IS_ARRAY) {
+ zval **header;
+
+ for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(s->wrapperdata));
+ SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(s->wrapperdata), (void *) &header);
+ zend_hash_move_forward(Z_ARRVAL_P(s->wrapperdata))) {
+ if (Z_TYPE_PP(header) == IS_STRING && !strncasecmp(Z_STRVAL_PP(header), ZEND_STRS("Content-Type:")-1)) {
+ char *needle = estrdup("charset="), *haystack = estrndup(Z_STRVAL_PP(header), Z_STRLEN_PP(header));
+ char *encoding = php_stristr(haystack, needle, Z_STRLEN_PP(header), sizeof("charset=")-1);
+
+ if (encoding) {
+ enc = xmlParseCharEncoding(encoding + sizeof("charset=")-1);
+ if (enc <= XML_CHAR_ENCODING_NONE) {
+ enc = XML_CHAR_ENCODING_NONE;
+ }
+ }
+
+ efree(haystack);
+ efree(needle);
+
+ break; /* found content-type */
+ }
+ }
+ }
+ }
+
/* Allocate the Input buffer front-end. */
ret = xmlAllocParserInputBuffer(enc);
if (ret != NULL) {
|