Commit b8c9be97 authored by Daniel Veillard's avatar Daniel Veillard

fixed XML Base computation which was broken added a base function to the

* tree.c: fixed XML Base computation which was broken
* debugXML.c: added a base function to the shell
* Makefile.am result/scripts/* test/scripts/*: added scripts
  based regression tests, and adding 2 XML Base tests
Daniel
parent 19e96c30
Mon Jul 9 17:59:08 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tree.c: fixed XML Base computation which was broken
* debugXML.c: added a base function to the shell
* Makefile.am result/scripts/* test/scripts/*: added scripts
based regression tests, and adding 2 XML Base tests
Mon Jul 9 12:31:05 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tree.c: set properties doc and call xmlSetListDoc for properties
......
......@@ -89,7 +89,7 @@ $(libxml2_la_SOURCES): $(srcdir)/libxml
testall : tests SVGtests SAXtests
tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests XIncludetests
tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests XIncludetests Scripttests
HTMLtests : testHTML
@(echo > .memdump)
......@@ -365,6 +365,27 @@ XIncludetests : xmllint
rm result.$$name ; \
fi ; fi ; done)
Scripttests : xmllint
@(echo > .memdump)
@echo "##"
@echo "## Scripts regression tests"
@echo "## Some of the base computations may be different if srcdir != ."
@echo "##"
@(for i in $(srcdir)/test/scripts/*.script ; do \
name=`basename $$i .script`; \
xml=$(srcdir)/test/scripts/`basename $$i .script`.xml; \
if [ -f $$xml ] ; then \
if [ ! -f $(srcdir)/result/scripts/$$name ] ; then \
echo New test file $$name ; \
$(top_builddir)/xmllint --shell $$xml < $$i > $(srcdir)/result/scripts/$$name ; \
else \
echo Testing $$name ; \
$(top_builddir)/xmllint --shell $$xml < $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/scripts/$$name result.$$name ; \
rm result.$$name ; \
fi ; fi ; done)
SVGtests : xmllint
@echo "##"
@echo "## SVG parsing regression tests"
......
......@@ -1091,6 +1091,34 @@ xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED , char *arg ATTRIBUTE_UNUSED,
return(0);
}
/**
* xmlShellBase:
* @ctxt: the shell context
* @arg: unused
* @node: a node
* @node2: unused
*
* Implements the XML shell function "base"
* dumps the current XML base of the node
*
* Returns 0
*/
static int
xmlShellBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
xmlNodePtr node2 ATTRIBUTE_UNUSED) {
xmlChar *base;
base = xmlNodeGetBase(node->doc, node);
if (base == NULL) {
printf(" No base found !!!\n");
} else {
printf("%s\n", base);
xmlFree(base);
}
return(0);
}
/**
* xmlShellDir:
* @ctxt: the shell context
......@@ -1654,6 +1682,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
printf("%s\n", dir);
} else if (!strcmp(command, "du")) {
xmlShellDu(ctxt, NULL, ctxt->node, NULL);
} else if (!strcmp(command, "base")) {
xmlShellBase(ctxt, NULL, ctxt->node, NULL);
} else if ((!strcmp(command, "ls")) ||
(!strcmp(command, "dir"))) {
int dir = (!strcmp(command, "dir"));
......@@ -1724,7 +1754,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
break;
}
#ifdef LIBXML_XPATH_ENABLED
xmlXPathFreeNodeSetList(list);
xmlXPathFreeObject(list);
#endif
} else {
xmlGenericError(xmlGenericErrorContext,
......@@ -1790,7 +1820,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
break;
}
#ifdef LIBXML_XPATH_ENABLED
xmlXPathFreeNodeSetList(list);
xmlXPathFreeObject(list);
#endif
} else {
xmlGenericError(xmlGenericErrorContext,
......@@ -1860,7 +1890,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
break;
}
#ifdef LIBXML_XPATH_ENABLED
xmlXPathFreeNodeSetList(list);
xmlXPathFreeObject(list);
#endif
} else {
xmlGenericError(xmlGenericErrorContext,
......@@ -1880,6 +1910,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
if (ctxt->loaded) {
xmlFreeDoc(ctxt->doc);
}
if (ctxt->filename != NULL)
xmlFree(ctxt->filename);
xmlFree(ctxt);
if (cmdline != NULL)
free(cmdline); /* not xmlFree here ! */
......
/ > base
./test/scripts/base.xml
/ > cd //e
e > base
http://example.com/base/
e > cd .//img
img > base
http://example.com/base/images/
img > exit
/ > base
./test/scripts/base2.xml
/ > cd //e
e > base
test/scripts/html/
e > cd .//img
img > base
test/scripts/images/
img > exit
base
cd //e
base
cd .//img
base
exit
<doc>
<e xml:base="http://example.com/base/">
<images xml:base="images/">
<img href="img1.gif"/>
</images>
</e>
</doc>
base
cd //e
base
cd .//img
base
exit
<doc>
<e xml:base="html/">
<images xml:base="../images/">
<img href="img1.gif"/>
</images>
</e>
</doc>
......@@ -28,6 +28,7 @@
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/uri.h>
#include <libxml/entities.h>
#include <libxml/valid.h>
#include <libxml/xmlerror.h>
......@@ -3317,7 +3318,8 @@ xmlNodeSetBase(xmlNodePtr cur, xmlChar* uri) {
*/
xmlChar *
xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
xmlChar *base;
xmlChar *oldbase = NULL;
xmlChar *base, *newbase;
if ((cur == NULL) && (doc == NULL))
return(NULL);
......@@ -3350,17 +3352,38 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
return(xmlStrdup(ent->URI));
}
if (cur->type == XML_ELEMENT_NODE) {
base = xmlGetProp(cur, BAD_CAST "xml:base");
base = xmlGetNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE);
if (base != NULL) {
/* TODO : apply cascade in the base resolution ! */
return(base);
if (oldbase != NULL) {
newbase = xmlBuildURI(oldbase, base);
if (newbase != NULL) {
xmlFree(oldbase);
xmlFree(base);
oldbase = newbase;
} else {
xmlFree(oldbase);
xmlFree(base);
return(NULL);
}
} else {
oldbase = base;
}
if ((!xmlStrncmp(oldbase, BAD_CAST "http://", 7)) ||
(!xmlStrncmp(oldbase, BAD_CAST "ftp://", 6)) ||
(!xmlStrncmp(oldbase, BAD_CAST "urn:", 4)))
return(oldbase);
}
}
cur = cur->parent;
}
if ((doc != NULL) && (doc->URL != NULL))
return(xmlStrdup(doc->URL));
return(NULL);
if ((doc != NULL) && (doc->URL != NULL)) {
if (oldbase == NULL)
return(xmlStrdup(doc->URL));
newbase = xmlBuildURI(oldbase, doc->URL);
xmlFree(oldbase);
return(newbase);
}
return(oldbase);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment