mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-28 00:21:53 +03:00
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
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
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>
|
Mon Jul 9 12:31:05 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||||
|
|
||||||
* tree.c: set properties doc and call xmlSetListDoc for properties
|
* tree.c: set properties doc and call xmlSetListDoc for properties
|
||||||
|
23
Makefile.am
23
Makefile.am
@ -89,7 +89,7 @@ $(libxml2_la_SOURCES): $(srcdir)/libxml
|
|||||||
|
|
||||||
testall : tests SVGtests SAXtests
|
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
|
HTMLtests : testHTML
|
||||||
@(echo > .memdump)
|
@(echo > .memdump)
|
||||||
@ -365,6 +365,27 @@ XIncludetests : xmllint
|
|||||||
rm result.$$name ; \
|
rm result.$$name ; \
|
||||||
fi ; fi ; done)
|
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
|
SVGtests : xmllint
|
||||||
@echo "##"
|
@echo "##"
|
||||||
@echo "## SVG parsing regression tests"
|
@echo "## SVG parsing regression tests"
|
||||||
|
38
debugXML.c
38
debugXML.c
@ -1091,6 +1091,34 @@ xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED , char *arg ATTRIBUTE_UNUSED,
|
|||||||
return(0);
|
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:
|
* xmlShellDir:
|
||||||
* @ctxt: the shell context
|
* @ctxt: the shell context
|
||||||
@ -1654,6 +1682,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
|
|||||||
printf("%s\n", dir);
|
printf("%s\n", dir);
|
||||||
} else if (!strcmp(command, "du")) {
|
} else if (!strcmp(command, "du")) {
|
||||||
xmlShellDu(ctxt, NULL, ctxt->node, NULL);
|
xmlShellDu(ctxt, NULL, ctxt->node, NULL);
|
||||||
|
} else if (!strcmp(command, "base")) {
|
||||||
|
xmlShellBase(ctxt, NULL, ctxt->node, NULL);
|
||||||
} else if ((!strcmp(command, "ls")) ||
|
} else if ((!strcmp(command, "ls")) ||
|
||||||
(!strcmp(command, "dir"))) {
|
(!strcmp(command, "dir"))) {
|
||||||
int dir = (!strcmp(command, "dir"));
|
int dir = (!strcmp(command, "dir"));
|
||||||
@ -1724,7 +1754,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef LIBXML_XPATH_ENABLED
|
#ifdef LIBXML_XPATH_ENABLED
|
||||||
xmlXPathFreeNodeSetList(list);
|
xmlXPathFreeObject(list);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
@ -1790,7 +1820,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef LIBXML_XPATH_ENABLED
|
#ifdef LIBXML_XPATH_ENABLED
|
||||||
xmlXPathFreeNodeSetList(list);
|
xmlXPathFreeObject(list);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
@ -1860,7 +1890,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef LIBXML_XPATH_ENABLED
|
#ifdef LIBXML_XPATH_ENABLED
|
||||||
xmlXPathFreeNodeSetList(list);
|
xmlXPathFreeObject(list);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
@ -1880,6 +1910,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
|
|||||||
if (ctxt->loaded) {
|
if (ctxt->loaded) {
|
||||||
xmlFreeDoc(ctxt->doc);
|
xmlFreeDoc(ctxt->doc);
|
||||||
}
|
}
|
||||||
|
if (ctxt->filename != NULL)
|
||||||
|
xmlFree(ctxt->filename);
|
||||||
xmlFree(ctxt);
|
xmlFree(ctxt);
|
||||||
if (cmdline != NULL)
|
if (cmdline != NULL)
|
||||||
free(cmdline); /* not xmlFree here ! */
|
free(cmdline); /* not xmlFree here ! */
|
||||||
|
9
result/scripts/base
Normal file
9
result/scripts/base
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/ > 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
|
9
result/scripts/base2
Normal file
9
result/scripts/base2
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/ > base
|
||||||
|
./test/scripts/base2.xml
|
||||||
|
/ > cd //e
|
||||||
|
e > base
|
||||||
|
test/scripts/html/
|
||||||
|
e > cd .//img
|
||||||
|
img > base
|
||||||
|
test/scripts/images/
|
||||||
|
img > exit
|
7
test/scripts/base.script
Normal file
7
test/scripts/base.script
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
base
|
||||||
|
cd //e
|
||||||
|
base
|
||||||
|
cd .//img
|
||||||
|
base
|
||||||
|
exit
|
||||||
|
|
7
test/scripts/base.xml
Normal file
7
test/scripts/base.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<doc>
|
||||||
|
<e xml:base="http://example.com/base/">
|
||||||
|
<images xml:base="images/">
|
||||||
|
<img href="img1.gif"/>
|
||||||
|
</images>
|
||||||
|
</e>
|
||||||
|
</doc>
|
7
test/scripts/base2.script
Normal file
7
test/scripts/base2.script
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
base
|
||||||
|
cd //e
|
||||||
|
base
|
||||||
|
cd .//img
|
||||||
|
base
|
||||||
|
exit
|
||||||
|
|
7
test/scripts/base2.xml
Normal file
7
test/scripts/base2.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<doc>
|
||||||
|
<e xml:base="html/">
|
||||||
|
<images xml:base="../images/">
|
||||||
|
<img href="img1.gif"/>
|
||||||
|
</images>
|
||||||
|
</e>
|
||||||
|
</doc>
|
37
tree.c
37
tree.c
@ -28,6 +28,7 @@
|
|||||||
#include <libxml/xmlmemory.h>
|
#include <libxml/xmlmemory.h>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
|
#include <libxml/uri.h>
|
||||||
#include <libxml/entities.h>
|
#include <libxml/entities.h>
|
||||||
#include <libxml/valid.h>
|
#include <libxml/valid.h>
|
||||||
#include <libxml/xmlerror.h>
|
#include <libxml/xmlerror.h>
|
||||||
@ -3317,7 +3318,8 @@ xmlNodeSetBase(xmlNodePtr cur, xmlChar* uri) {
|
|||||||
*/
|
*/
|
||||||
xmlChar *
|
xmlChar *
|
||||||
xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
|
xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
|
||||||
xmlChar *base;
|
xmlChar *oldbase = NULL;
|
||||||
|
xmlChar *base, *newbase;
|
||||||
|
|
||||||
if ((cur == NULL) && (doc == NULL))
|
if ((cur == NULL) && (doc == NULL))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
@ -3350,17 +3352,38 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
|
|||||||
return(xmlStrdup(ent->URI));
|
return(xmlStrdup(ent->URI));
|
||||||
}
|
}
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
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) {
|
if (base != NULL) {
|
||||||
/* TODO : apply cascade in the base resolution ! */
|
if (oldbase != NULL) {
|
||||||
return(base);
|
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;
|
cur = cur->parent;
|
||||||
}
|
}
|
||||||
if ((doc != NULL) && (doc->URL != NULL))
|
if ((doc != NULL) && (doc->URL != NULL)) {
|
||||||
return(xmlStrdup(doc->URL));
|
if (oldbase == NULL)
|
||||||
return(NULL);
|
return(xmlStrdup(doc->URL));
|
||||||
|
newbase = xmlBuildURI(oldbase, doc->URL);
|
||||||
|
xmlFree(oldbase);
|
||||||
|
return(newbase);
|
||||||
|
}
|
||||||
|
return(oldbase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user