xmlOutputBufferCreateFilename() didn't unescaped URIs before doing the

* xmlIO.c: xmlOutputBufferCreateFilename() didn't unescaped
  URIs before doing the lookups (pointed by Mark Vakoc)
Daniel
diff --git a/ChangeLog b/ChangeLog
index b564868..b3b2487 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Aug 15 10:46:07 CEST 2001 Daniel Veillard <daniel@veillard.com>
+
+	* xmlIO.c: xmlOutputBufferCreateFilename() didn't unescaped
+	  URIs before doing the lookups (pointed by Mark Vakoc)
+
 Tue Aug 14 18:37:23 CEST 2001 Daniel Veillard <daniel@veillard.com>
 
 	* xpath.c: serious changes on Result Value Trees and NodeSets
diff --git a/xmlIO.c b/xmlIO.c
index b78ccbe..6360d04 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -1663,8 +1663,9 @@
                               xmlCharEncodingHandlerPtr encoder,
 			      int compression) {
     xmlOutputBufferPtr ret;
-    int i;
+    int i = 0;
     void *context = NULL;
+    char *unescaped;
 
     int is_http_uri = 0;	/*   Can't change if HTTP disabled  */
 
@@ -1679,40 +1680,79 @@
     is_http_uri = xmlIOHTTPMatch( URI );
 #endif
 
-#ifdef HAVE_ZLIB_H
-    if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) {
-        context = xmlGzfileOpenW(URI, compression);
-	if (context != NULL) {
-	    ret = xmlAllocOutputBuffer(encoder);
-	    if (ret != NULL) {
-		ret->context = context;
-		ret->writecallback = xmlGzfileWrite;
-		ret->closecallback = xmlGzfileClose;
-	    }
-	    return(ret);
-	}
-    }
-#endif
 
     /*
-     * Try to find one of the output accept method accepting that scheme
+     * Try to find one of the output accept method accepting taht scheme
      * Go in reverse to give precedence to user defined handlers.
+     * try with an unescaped version of the URI
      */
-    for (i = xmlOutputCallbackNr - 1;i >= 0;i--) {
-	if ((xmlOutputCallbackTable[i].matchcallback != NULL) &&
-	    (xmlOutputCallbackTable[i].matchcallback(URI) != 0)) {
-
-#if ( defined( LIBXML_HTTP_ENABLED ) && defined( HAVE_ZLIB_H ) )
-	    /*  Need to pass compression parameter into HTTP open calls  */
-
-	    if ( xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch )
-		context = xmlIOHTTPOpenW( URI, compression );
-	    else
+    unescaped = xmlURIUnescapeString(URI, 0, NULL);
+    if (unescaped != NULL) {
+#ifdef HAVE_ZLIB_H
+	if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) {
+	    context = xmlGzfileOpenW(unescaped, compression);
+	    if (context != NULL) {
+		ret = xmlAllocOutputBuffer(encoder);
+		if (ret != NULL) {
+		    ret->context = context;
+		    ret->writecallback = xmlGzfileWrite;
+		    ret->closecallback = xmlGzfileClose;
+		}
+		xmlFree(unescaped);
+		return(ret);
+	    }
+	}
 #endif
-		context = xmlOutputCallbackTable[i].opencallback(URI);
+	for (i = xmlOutputCallbackNr - 1;i >= 0;i--) {
+	    if ((xmlOutputCallbackTable[i].matchcallback != NULL) &&
+		(xmlOutputCallbackTable[i].matchcallback(unescaped) != 0)) {
+#if defined(LIBXML_HTTP_ENABLED) && defined(HAVE_ZLIB_H)
+		/*  Need to pass compression parameter into HTTP open calls  */
+		if (xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch)
+		    context = xmlIOHTTPOpenW(unescaped, compression);
+		else
+#endif
+		    context = xmlOutputCallbackTable[i].opencallback(unescaped);
+		if (context != NULL)
+		    break;
+	    }
+	}
+	xmlFree(unescaped);
+    }
 
-	    if (context != NULL)
-		break;
+    /*
+     * If this failed try with a non-escaped URI this may be a strange
+     * filename
+     */
+    if (context == NULL) {
+#ifdef HAVE_ZLIB_H
+	if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) {
+	    context = xmlGzfileOpenW(URI, compression);
+	    if (context != NULL) {
+		ret = xmlAllocOutputBuffer(encoder);
+		if (ret != NULL) {
+		    ret->context = context;
+		    ret->writecallback = xmlGzfileWrite;
+		    ret->closecallback = xmlGzfileClose;
+		}
+		return(ret);
+	    }
+	}
+#endif
+	for (i = xmlOutputCallbackNr - 1;i >= 0;i--) {
+	    if ((xmlOutputCallbackTable[i].matchcallback != NULL) &&
+		(xmlOutputCallbackTable[i].matchcallback(URI) != 0)) {
+		context = xmlOutputCallbackTable[i].opencallback(URI);
+#if defined(LIBXML_HTTP_ENABLED) && defined(HAVE_ZLIB_H)
+		/*  Need to pass compression parameter into HTTP open calls  */
+		if (xmlOutputCallbackTable[i].matchcallback == xmlIOHTTPMatch)
+		    context = xmlIOHTTPOpenW(URI, compression);
+		else
+#endif
+		    context = xmlOutputCallbackTable[i].opencallback(URI);
+		if (context != NULL)
+		    break;
+	    }
 	}
     }