URI work cleanup and regresssion tests,
- uri.c testUri.c: applied Wayne Davidson patches
- test/URI/uri.data result/URI/uri.data: first set of tests/results
- Makefile.in: added URItest and included thenin "make tests"
Daniel
diff --git a/ChangeLog b/ChangeLog
index 9d7bfb3..790988c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-Sun Sep 3 19:19:29 CEST 2000
+Mon Sep 4 13:01:45 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
+
+ * uri.c testUri.c: applied Wayne Davidson patches
+ * test/URI/uri.data result/URI/uri.data: first set of tests/results
+ * Makefile.in: added URItest and included thenin "make tests"
+
+Sun Sep 3 19:19:29 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* xmlversion.h.in: closed bug 22941
diff --git a/Makefile.am b/Makefile.am
index 1f06fa6..f200249 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -98,7 +98,7 @@
testall : tests SVGtests SAXtests XPathtests
-tests: XMLtests XMLenttests HTMLtests Validtests
+tests: XMLtests XMLenttests HTMLtests Validtests URItests
HTMLtests : testHTML
@(rm -f .memdump ; touch .memdump)
@@ -214,6 +214,25 @@
rm result.$$name result2.$$name ; \
fi ; fi ; done)
+URItests : testURI
+ @(rm -f .memdump ; touch .memdump)
+ @echo "##"
+ @echo "## URI module regression tests"
+ @echo "##"
+ @(for i in $(srcdir)/test/URI/*.data ; do \
+ name=`basename $$i`; \
+ if [ ! -d $$i ] ; then \
+ if [ ! -f $(srcdir)/result/URI/$$name ] ; then \
+ echo New test file $$name ; \
+ $(top_builddir)/testURI -base 'http://foo.com/path/to/index.html#help' < $$i > $(srcdir)/result/URI/$$name ; \
+ else \
+ echo Testing $$name ; \
+ $(top_builddir)/testURI -base 'http://foo.com/path/to/index.html#help' < $$i > result.$$name ; \
+ grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
+ diff $(srcdir)/result/URI/$$name result.$$name ; \
+ rm result.$$name ; \
+ fi ; fi ; done)
+
XPathtests : testXPath
@echo "##"
@echo "## XPath regression tests"
diff --git a/result/URI/uri.data b/result/URI/uri.data
new file mode 100644
index 0000000..bce924a
--- /dev/null
+++ b/result/URI/uri.data
@@ -0,0 +1,13 @@
+http://foo.com/path/to/index.html#help
+http://foo.com/path/to/
+http://foo.com/path/to/bar
+http://foo.com/path/to/bar#baz
+http://foo.com/path/to/bar?baz
+http://foo.com/path/to/index.html#baz
+http://foo.com/path/to/index.html?baz
+http://foo.com/path/up.a.notch.html#wow
+http://foo.com/path/up.a.notch.html?wow
+http://foo.com/root.cgi#OK
+http://foo.com/root.cgi?OK
+https://elsewhere.com/#deep
+https://elsewhere.com/?deep
diff --git a/test/URI/uri.data b/test/URI/uri.data
new file mode 100644
index 0000000..570eff0
--- /dev/null
+++ b/test/URI/uri.data
@@ -0,0 +1,13 @@
+
+.
+bar
+bar#baz
+bar?baz
+#baz
+?baz
+../up.a.notch.html#wow
+../up.a.notch.html?wow
+/root.cgi#OK
+/root.cgi?OK
+https://elsewhere.com/#deep
+https://elsewhere.com/?deep
diff --git a/testURI.c b/testURI.c
index 50b508e..349ca02 100644
--- a/testURI.c
+++ b/testURI.c
@@ -58,17 +58,24 @@
i--;
str[i] = 0;
}
- if (i <= 0)
- continue;
- ret = xmlParseURIReference(uri, str);
- if (ret != 0)
- printf("%s : error %d\n", str, ret);
- else {
- xmlPrintURI(stdout, uri);
- printf("\n");
+ if (base == NULL) {
+ ret = xmlParseURIReference(uri, str);
+ if (ret != 0)
+ printf("%s : error %d\n", str, ret);
+ else {
+ xmlPrintURI(stdout, uri);
+ printf("\n");
+ }
+ } else {
+ composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
+ if (composite != NULL) {
+ printf("%s\n", composite);
+ xmlFree(composite);
+ }
+ else
+ printf("::ERROR::\n");
}
-
}
} else {
while (argv[arg] != NULL) {
diff --git a/uri.c b/uri.c
index 4f4452a..8ccd79b 100644
--- a/uri.c
+++ b/uri.c
@@ -1216,7 +1216,7 @@
} else if (cur[0] == '/') {
cur++;
ret = xmlParseURIPathSegments(uri, &cur, 1);
- } else {
+ } else if (cur[0] != '#' && cur[0] != '?') {
ret = xmlParseURIRelSegment(uri, &cur);
if (ret != 0)
return(ret);
@@ -1467,7 +1467,6 @@
xmlURIPtr bas = NULL;
xmlURIPtr res = NULL;
-
/*
* 1) The URI reference is parsed into the potential four components and
* fragment identifier, as described in Section 4.3.
@@ -1475,9 +1474,11 @@
ref = xmlCreateURI();
if (ref == NULL)
goto done;
- ret = xmlParseURIReference(ref, (const char *) URI);
- if (ret != 0)
- goto done;
+ if (*URI) {
+ ret = xmlParseURIReference(ref, (const char *) URI);
+ if (ret != 0)
+ goto done;
+ }
bas = xmlCreateURI();
if (bas == NULL)
goto done;
@@ -1488,22 +1489,29 @@
/*
* 2) If the path component is empty and the scheme, authority, and
* query components are undefined, then it is a reference to the
- * current document and we are done. Otherwise, the reference URI's
- * query and fragment components are defined as found (or not found)
- * within the URI reference and not inherited from the base URI.
+ * current document. However, since we need to inherit these
+ * values from the base, we keep on going.
+ *
+ * NOTE: this is a divergence from the RFC which says:
+ * current document and we are done. Otherwise, the reference URI's
+ * query and fragment components are defined as found (or not found)
+ * within the URI reference and not inherited from the base URI.
*/
res = xmlCreateURI();
if (res == NULL)
goto done;
+#if 0
if ((ref->scheme == NULL) && (ref->path == NULL) &&
((ref->authority == NULL) && (ref->server == NULL)) &&
(ref->query == NULL)) {
if (ref->fragment == NULL)
goto done;
- res->fragment = xmlMemStrdup(ref->fragment);
+ res->fragment = xmlMemStrdup(ref->fragment);
val = xmlSaveUri(res);
goto done;
}
+#endif
+
/*
* 3) If the scheme component is defined, indicating that the reference
@@ -1517,8 +1525,6 @@
}
if (bas->scheme != NULL)
res->scheme = xmlMemStrdup(bas->scheme);
- else
- res->scheme = NULL;
/*
* 4) If the authority component is defined, then the reference is a
@@ -1556,8 +1562,27 @@
/*
* 5) If the path component begins with a slash character ("/"), then
* the reference is an absolute-path and we skip to step 7.
+ *
+ * If it is not defined, inherit the whole path from the base.
+ * The query and the fragment are inherited too, unless specified
+ * in the reference.
*/
- if ((ref->path != NULL) && (ref->path[0] == '/')) {
+ if (ref->path == NULL) {
+ res->path = xmlMemStrdup(bas->path);
+ if (ref->query == NULL && ref->fragment == NULL) {
+ if (bas->query != NULL)
+ res->query = xmlMemStrdup(bas->query);
+ if (bas->fragment != NULL)
+ res->fragment = xmlMemStrdup(bas->fragment);
+ } else {
+ if (ref->query != NULL)
+ res->query = xmlMemStrdup(ref->query);
+ if (ref->fragment != NULL)
+ res->fragment = xmlMemStrdup(ref->fragment);
+ }
+ goto step_7;
+ }
+ if (ref->path[0] == '/') {
res->path = xmlMemStrdup(ref->path);
if (ref->query != NULL)
res->query = xmlMemStrdup(ref->query);
@@ -1634,6 +1659,11 @@
*/
xmlNormalizeURIPath(res->path);
+ if (ref->query != NULL)
+ res->query = xmlMemStrdup(ref->query);
+ if (ref->fragment != NULL)
+ res->fragment = xmlMemStrdup(ref->fragment);
+
step_7:
/*