From 4e9b1bc21c1ff8eea35e9cbeae5629fb6d145803 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 9 Jun 2003 10:30:33 +0000 Subject: [PATCH] trying to fix #114277 about when file remapping and escaping should really * parser.c xmlIO.c: trying to fix #114277 about when file remapping and escaping should really be attempted. Daniel --- ChangeLog | 5 +++++ parser.c | 11 +---------- xmlIO.c | 36 ++++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index c03b92a6..134b8462 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jun 9 12:28:58 CEST 2003 Daniel Veillard + + * parser.c xmlIO.c: trying to fix #114277 about when file + remapping and escaping should really be attempted. + Mon Jun 9 11:06:09 CEST 2003 Daniel Veillard * doc/*: applied a patch from Gman for building docs diff --git a/parser.c b/parser.c index 40ffd20d..1e10569c 100644 --- a/parser.c +++ b/parser.c @@ -10558,7 +10558,6 @@ xmlCreateFileParserCtxt(const char *filename) { xmlParserCtxtPtr ctxt; xmlParserInputPtr inputStream; - char *canonicFilename; char *directory = NULL; ctxt = xmlNewParserCtxt(); @@ -10569,16 +10568,8 @@ xmlCreateFileParserCtxt(const char *filename) return(NULL); } - canonicFilename = (char *) xmlCanonicPath((const xmlChar *) filename); - if (canonicFilename == NULL) { - if (xmlDefaultSAXHandler.error != NULL) { - xmlDefaultSAXHandler.error(NULL, "out of memory\n"); - } - return(NULL); - } - inputStream = xmlLoadExternalEntity(canonicFilename, NULL, ctxt); - xmlFree(canonicFilename); + inputStream = xmlLoadExternalEntity(filename, NULL, ctxt); if (inputStream == NULL) { xmlFreeParserCtxt(ctxt); return(NULL); diff --git a/xmlIO.c b/xmlIO.c index f096e509..5a4f812e 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -532,20 +532,22 @@ xmlGzfileOpen_real (const char *filename) { * xmlGzfileOpen: * @filename: the URI for matching * - * Wrapper around xmlGzfileOpen that try it with an unescaped - * version of @filename, if this fails fallback to @filename + * Wrapper around xmlGzfileOpen if the open fais, it will + * try to unescape @filename */ static void * xmlGzfileOpen (const char *filename) { char *unescaped; void *retval; - unescaped = xmlURIUnescapeString(filename, 0, NULL); - if (unescaped != NULL) { - retval = xmlGzfileOpen_real(unescaped); - } else { - retval = xmlGzfileOpen_real(filename); + + retval = xmlGzfileOpen_real(filename); + if (retval == NULL) { + unescaped = xmlURIUnescapeString(filename, 0, NULL); + if (unescaped != NULL) { + retval = xmlGzfileOpen_real(unescaped); + } + xmlFree(unescaped); } - xmlFree(unescaped); return retval; } @@ -2487,7 +2489,6 @@ xmlParserGetDirectory(const char *filename) { * * ****************************************************************/ -#ifdef LIBXML_CATALOG_ENABLED static int xmlSysIDExists(const char *URL) { #ifdef HAVE_STAT int ret; @@ -2517,7 +2518,6 @@ static int xmlSysIDExists(const char *URL) { #endif return(0); } -#endif /** * xmlDefaultExternalEntityLoader: @@ -2669,6 +2669,22 @@ xmlGetExternalEntityLoader(void) { xmlParserInputPtr xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt) { + if ((URL != NULL) && (xmlSysIDExists(URL) == 0)) { + char *canonicFilename; + xmlParserInputPtr ret; + + canonicFilename = (char *) xmlCanonicPath((const xmlChar *) URL); + if (canonicFilename == NULL) { + if (xmlDefaultSAXHandler.error != NULL) { + xmlDefaultSAXHandler.error(NULL, "out of memory\n"); + } + return(NULL); + } + + ret = xmlCurrentExternalEntityLoader(canonicFilename, ID, ctxt); + xmlFree(canonicFilename); + return(ret); + } return(xmlCurrentExternalEntityLoader(URL, ID, ctxt)); }