- Makefile.am include/Makefile.am: small change to have
  include/libxml rebuilt if working from CVS.
- uri.c: applied another patch from Carl Douglas for URI escaping,
  this should close bug #51876
Daniel
diff --git a/ChangeLog b/ChangeLog
index 559ce86..002347a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri May 25 09:36:26 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+	* Makefile.am include/Makefile.am: small change to have
+	  include/libxml rebuilt if working from CVS.
+	* uri.c: applied another patch from Carl Douglas for URI escaping,
+	  this should close bug #51876
+
 Wed May 23 15:40:27 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
 	* xinclude.c: fixed XInclude recursive behaviour bug #54678
diff --git a/Makefile.am b/Makefile.am
index 67dceba..cf6c79d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = . include doc example
+SUBDIRS = include . doc example
 
 INCLUDES = -I@srcdir@/include -I./include @Z_CFLAGS@ @CORBA_CFLAGS@ 
 
diff --git a/include/Makefile.am b/include/Makefile.am
index 12d2b1d..5f7e733 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -34,3 +34,10 @@
 	$(mkinstalldirs) $(DESTDIR)$(xmlincdir) $(DESTDIR)$(xmlincdir)/libxml
 
 EXTRA_DIST = win32config.h libxml/xmlversion.h.in
+
+all: $(srcdir)/libxml
+
+$(xmlinc_HEADERS): $(srcdir)/libxml
+
+$(srcdir)/libxml:
+	@(cd $(srcdir); ln -s .. libxml)
diff --git a/uri.c b/uri.c
index 779ca6f..b455460 100644
--- a/uri.c
+++ b/uri.c
@@ -1051,17 +1051,102 @@
  * It will try to escape the chars needing this, but this is heuristic
  * based it's impossible to be sure.
  *
- * TODO: make the proper implementation of this function by calling
- *       xmlParseURIReference() and escaping each section accordingly
- *       to the rules (c.f. bug 51876)
- *
  * Returns an copy of the string, but escaped
+ *
+ * 25 May 2001
+ * Uses xmlParseURI and xmlURIEscapeStr to try to escape correctly
+ * according to RFC2396.
+ *   - Carl Douglas
  */
 xmlChar *
 xmlURIEscape(const xmlChar *str) {
-    xmlChar *ret;
+    xmlChar *ret, *segment = NULL;
+    xmlURIPtr uri;
 
-    ret = xmlURIEscapeStr(str, BAD_CAST "#");
+#define NULLCHK(p) if(!p) { \
+                   xmlGenericError(xmlGenericErrorContext, \
+                        "xmlURIEscape: out of memory\n"); \
+                   return NULL; }
+
+    uri = xmlParseURI( (const char *) str);
+
+    if(!uri)
+	return NULL;
+
+    ret = NULL;
+
+    if(uri->scheme) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->scheme, BAD_CAST "+-.");
+	NULLCHK(segment)
+	xmlStrcat(ret, segment);
+	xmlStrcat(ret, BAD_CAST ":");
+	xmlFree(segment);
+    }
+
+    if(uri->authority) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->authority, BAD_CAST "/?;:@");
+	NULLCHK(segment)
+	xmlStrcat(ret, BAD_CAST "//");
+	xmlStrcat(ret, segment);
+	xmlFree(segment);
+    }
+
+    if(uri->user) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->user, BAD_CAST ";:&=+$,");
+	NULLCHK(segment)
+	xmlStrcat(ret, segment);
+	xmlStrcat(ret, BAD_CAST "@");
+	xmlFree(segment);
+    }
+
+    if(uri->server) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->server, BAD_CAST "/?;:@");
+	NULLCHK(segment)
+	xmlStrcat(ret, BAD_CAST "//");
+	xmlStrcat(ret, segment);
+	xmlFree(segment);
+    }
+
+    if(uri->port) {
+	xmlChar port[10];
+	snprintf(segment, 10, "%d", uri->port);
+	xmlStrcat(ret, BAD_CAST ":");
+	xmlStrcat(ret, port);
+	xmlFree(segment);
+    }
+
+    if(uri->path) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
+	NULLCHK(segment)
+	xmlStrcat(ret, segment);
+	xmlFree(segment);
+    }
+
+    if(uri->query) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
+	NULLCHK(segment)
+	xmlStrcat(ret, BAD_CAST "?");
+	xmlStrcat(ret, segment);
+	xmlFree(segment);
+    }
+
+    if(uri->opaque) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->opaque, BAD_CAST "");
+	NULLCHK(segment)
+	xmlStrcat(ret, segment);
+	xmlStrcat(ret, BAD_CAST ":");
+	xmlFree(segment);
+    }
+
+    if(uri->fragment) {
+	segment = xmlURIEscapeStr( BAD_CAST uri->fragment, BAD_CAST "#");
+	NULLCHK(segment)
+	xmlStrcat(ret, BAD_CAST "#");
+	xmlStrcat(ret, segment);
+	xmlFree(segment);
+    }
+
+#undef NULLCHK
 
     return(ret);
 }