From 29eb399773955a19cc76b902956afbf20f22eaa6 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Mon, 19 May 2003 21:51:57 +0000 Subject: [PATCH] send some more data to the default handler libxml2 is braindead when it comes to handling entities --- ext/xml/compat.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ext/xml/compat.c b/ext/xml/compat.c index 9b9b1c41276..c22a4c29c67 100644 --- a/ext/xml/compat.c +++ b/ext/xml/compat.c @@ -209,6 +209,33 @@ _comment_handler(void *user, const xmlChar *comment) } } +static void +_build_entity(const xmlChar *name, int len, xmlChar **entity, int *entity_len) +{ + *entity_len = len + 2; + *entity = xmlMalloc(*entity_len + 1); + (*entity)[0] = '&'; + memcpy(*entity+1, name, len); + (*entity)[len+1] = ';'; + (*entity)[*entity_len] = '\0'; +} + +static xmlEntityPtr +_get_entity(void *user, const xmlChar *name) +{ + XML_Parser parser = (XML_Parser) user; + + if (parser->h_default) { + xmlChar *entity; + int len; + + _build_entity(name, xmlStrlen(name), &entity, &len); + parser->h_default(parser->user, (const xmlChar *) entity, len); + } + + return NULL; +} + static void _external_entity_ref_handler(void *user, const xmlChar *names, int type, const xmlChar *sys_id, const xmlChar *pub_id, xmlChar *content) { @@ -218,7 +245,7 @@ _external_entity_ref_handler(void *user, const xmlChar *names, int type, const x return; } - parser->h_external_entity_ref(parser, names, NULL, sys_id, pub_id); + parser->h_external_entity_ref(parser, names, "", sys_id, pub_id); } static xmlSAXHandler @@ -228,7 +255,7 @@ php_xml_compat_handlers = { NULL, /* hasInternalSubset */ NULL, /* hasExternalSubset */ NULL, /* resolveEntity */ - NULL, /* getEntity */ + _get_entity, /* getEntity */ _external_entity_ref_handler, /* entityDecl */ _notation_decl_handler, NULL, /* attributeDecl */