bug fixes, bugfixes, bugfixes ...
- parser.c: Fixed Bug#21552: libxml fails to decode &
- uri.c testUri.c patches, by Marc Sanfacon (1 left)
- parser.c HTMLparser.c: HTML/encoding push problems reportedi by Wayne Davison
Daniel
diff --git a/ChangeLog b/ChangeLog
index 305f71f..9371a9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Aug 23 00:23:41 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
+
+	* parser.c: Fixed Bug#21552: libxml fails to decode &amp;
+	* uri.c testUri.c patches, by Marc Sanfacon (1 left)
+	* parser.c HTMLparser.c: HTML/encoding push problems reportedi
+	  by Wayne Davison
+
 Sun Aug 20 17:03:38 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
 
 	* nanoftp.c nanohttp.c: small cleanup
diff --git a/HTMLparser.c b/HTMLparser.c
index 75edb10..6bb6a97 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -4220,8 +4220,10 @@
 
 	if ((terminate) || (ctxt->input->buf->buffer->use > 80))
 	    htmlParseTryOrFinish(ctxt, terminate);
-    } else if (ctxt->instate != XML_PARSER_EOF)
+    } else if (ctxt->instate != XML_PARSER_EOF) {
+	xmlParserInputBufferPush(ctxt->input->buf, 0, "");
         htmlParseTryOrFinish(ctxt, terminate);
+    }
     if (terminate) {
 	if ((ctxt->instate != XML_PARSER_EOF) &&
 	    (ctxt->instate != XML_PARSER_EPILOG) &&
diff --git a/parser.c b/parser.c
index 14aee65..ae1f5e7 100644
--- a/parser.c
+++ b/parser.c
@@ -443,6 +443,7 @@
     if (in->base == NULL) return(-1);
     if (in->cur == NULL) return(-1);
     if (in->buf->buffer == NULL) return(-1);
+    if (in->buf->readcallback == NULL) return(-1);
 
     CHECK_BUFFER(in);
 
@@ -2484,7 +2485,15 @@
 	    }
 	} else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) {
 	    ent = xmlParseStringEntityRef(ctxt, &str);
-	    if ((ent != NULL) && (ent->content != NULL)) {
+	    if ((ent != NULL) && (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
+		if (ent->content != NULL) {
+		    COPY_BUF(0,buffer,nbchars,ent->content[0]);
+		} else {
+		    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+			ctxt->sax->error(ctxt->userData,
+			    "internal error entity has no content\n");
+		}
+	    } else if ((ent != NULL) && (ent->content != NULL)) {
 		xmlChar *rep;
 
 		ctxt->depth++;
@@ -2833,15 +2842,24 @@
 		    ctxt->input->buf->raw = ctxt->input->buf->buffer;
 		    ctxt->input->buf->buffer = xmlBufferCreate();
 
-		    /*
-		     * convert just enough to get
-		     * '<?xml version="1.0" encoding="xxx"?>'
-		     * parsed with the autodetected encoding
-		     * into the parser reading buffer.
-		     */
-		    nbchars = xmlCharEncFirstLine(ctxt->input->buf->encoder,
-		                                  ctxt->input->buf->buffer,
-					          ctxt->input->buf->raw);
+		    if (ctxt->html) {
+			/*
+			 * converst as much as possbile of the buffer
+			 */
+			nbchars = xmlCharEncInFunc(ctxt->input->buf->encoder,
+				                   ctxt->input->buf->buffer,
+						   ctxt->input->buf->raw);
+		    } else {
+			/*
+			 * convert just enough to get
+			 * '<?xml version="1.0" encoding="xxx"?>'
+			 * parsed with the autodetected encoding
+			 * into the parser reading buffer.
+			 */
+			nbchars = xmlCharEncFirstLine(ctxt->input->buf->encoder,
+						      ctxt->input->buf->buffer,
+						      ctxt->input->buf->raw);
+		    }
 		    if (nbchars < 0) {
 			fprintf(stderr, "xmlSwitchToEncoding: encoder error\n");
 			return(-1);
diff --git a/testURI.c b/testURI.c
index 0cb904c..50b508e 100644
--- a/testURI.c
+++ b/testURI.c
@@ -27,6 +27,10 @@
     const char *base = NULL;
     xmlChar *composite;
 
+    if (argv[arg] == NULL) {
+	printf("Usage: %s [-base URI] URI ...\n", argv[0]);
+	exit(0);
+    }
     if ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base"))) {
 	arg++;
 	base = argv[arg];
@@ -78,8 +82,7 @@
 		}
 	    } else {
 		composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
-		if (base == NULL) {
-		} else {
+		if (composite != NULL) {
 		    printf("%s\n", composite);
 		    xmlFree(composite);
 		}
diff --git a/uri.c b/uri.c
index 1ed1410..28810c7 100644
--- a/uri.c
+++ b/uri.c
@@ -1024,6 +1024,7 @@
 	    *str = cur;
 	    return(-1);
 	}
+	path[len] = '\0';
 	if (uri->path != NULL)
 	    memcpy(path, uri->path, len2);
 	if (slash) {
@@ -1614,6 +1615,13 @@
      */
     if (ref->path != NULL) {
 	index = 0;
+	/*
+	 * Ensure the path includes a '/'
+	 */
+	if (res->path[0] != '/' && ref->path[0] != 0 &&
+	    ref->path[index] != '/') {
+	    res->path[out++] = '/';
+	}
 	while (ref->path[index] != 0) {
 	    res->path[out++] = ref->path[index++];
 	}