mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
fixed xmlHasNsProp() bugs for defaulted from DTD attribs, added a specific
* tree.c python/tests/Makefile.am python/tests/attribs.py: fixed xmlHasNsProp() bugs for defaulted from DTD attribs, added a specific regression test * python/generator.py: xmlHasNsProp() and xmlHasProp() shall not raise exceptions when failing to find the attribute. Daniel
This commit is contained in:
@ -1,3 +1,11 @@
|
||||
Thu Mar 7 23:19:28 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* tree.c python/tests/Makefile.am python/tests/attribs.py:
|
||||
fixed xmlHasNsProp() bugs for defaulted from DTD attribs,
|
||||
added a specific regression test
|
||||
* python/generator.py: xmlHasNsProp() and xmlHasProp() shall
|
||||
not raise exceptions when failing to find the attribute.
|
||||
|
||||
Thu Mar 7 16:11:35 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* configure.in xmllint.c: owen pointed out a problem with the
|
||||
|
@ -551,6 +551,11 @@ classes_destructors = {
|
||||
"URI": "xmlFreeURI",
|
||||
}
|
||||
|
||||
functions_noexcept = {
|
||||
"xmlHasProp": 1,
|
||||
"xmlHasNsProp": 1,
|
||||
}
|
||||
|
||||
function_classes = {}
|
||||
|
||||
function_classes["None"] = []
|
||||
@ -675,6 +680,7 @@ def buildWrappers():
|
||||
global primary_classes
|
||||
global classes_ancestor
|
||||
global classes_destructors
|
||||
global functions_noexcept
|
||||
|
||||
for type in classes_type.keys():
|
||||
function_classes[classes_type[type][2]] = []
|
||||
@ -799,7 +805,9 @@ def buildWrappers():
|
||||
#
|
||||
# Raise an exception
|
||||
#
|
||||
if string.find(name, "URI") >= 0:
|
||||
if functions_noexcept.has_key(name):
|
||||
classes.write(" if ret == None:return None\n");
|
||||
elif string.find(name, "URI") >= 0:
|
||||
classes.write(
|
||||
" if ret == None:raise uriError('%s() failed')\n"
|
||||
% (name))
|
||||
@ -912,7 +920,10 @@ def buildWrappers():
|
||||
#
|
||||
# Raise an exception
|
||||
#
|
||||
if string.find(name, "URI") >= 0:
|
||||
if functions_noexcept.has_key(name):
|
||||
classes.write(
|
||||
" if ret == None:return None\n");
|
||||
elif string.find(name, "URI") >= 0:
|
||||
classes.write(
|
||||
" if ret == None:raise uriError('%s() failed')\n"
|
||||
% (name))
|
||||
@ -935,7 +946,10 @@ def buildWrappers():
|
||||
#
|
||||
# Raise an exception
|
||||
#
|
||||
if string.find(name, "URI") >= 0:
|
||||
if functions_noexcept.has_key(name):
|
||||
classes.write(
|
||||
" if ret == None:return None");
|
||||
elif string.find(name, "URI") >= 0:
|
||||
classes.write(
|
||||
" if ret == None:raise uriError('%s() failed')\n"
|
||||
% (name))
|
||||
|
@ -2,6 +2,7 @@ EXAMPLE_DIR = $(prefix)/share/doc/libxml2-python-$(LIBXML_VERSION)/examples
|
||||
|
||||
PYTESTS= \
|
||||
build.py \
|
||||
attribs.py \
|
||||
tst.py \
|
||||
tstxpath.py \
|
||||
xpathext.py \
|
||||
|
34
python/tests/attribs.py
Executable file
34
python/tests/attribs.py
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python -u
|
||||
import sys
|
||||
import libxml2
|
||||
|
||||
# Memory debug specific
|
||||
libxml2.debugMemory(1)
|
||||
|
||||
#
|
||||
# Testing XML document serialization
|
||||
#
|
||||
doc = libxml2.parseDoc(
|
||||
"""<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE test [
|
||||
<!ELEMENT test (#PCDATA) >
|
||||
<!ATTLIST test xmlns:abc CDATA #FIXED "http://abc.org" >
|
||||
<!ATTLIST test abc:attr CDATA #FIXED "def" >
|
||||
]>
|
||||
<test />
|
||||
""")
|
||||
elem = doc.getRootElement()
|
||||
attr = elem.hasNsProp('attr', 'http://abc.org')
|
||||
if attr == None or attr.serialize()[:-1] != """<!ATTLIST test abc:attr CDATA #FIXED "def">""":
|
||||
print "Failed to find defaulted attribute abc:attr"
|
||||
sys.exit(1)
|
||||
|
||||
doc.freeDoc()
|
||||
|
||||
# Memory debug specific
|
||||
libxml2.cleanupParser()
|
||||
if libxml2.debugMemory(1) == 0:
|
||||
print "OK"
|
||||
else:
|
||||
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
||||
libxml2.dumpMemory()
|
44
tree.c
44
tree.c
@ -4802,7 +4802,6 @@ xmlAttrPtr
|
||||
xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) {
|
||||
xmlAttrPtr prop;
|
||||
xmlDocPtr doc;
|
||||
xmlNsPtr ns;
|
||||
|
||||
if (node == NULL)
|
||||
return(NULL);
|
||||
@ -4833,20 +4832,39 @@ xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) {
|
||||
doc = node->doc;
|
||||
if (doc != NULL) {
|
||||
if (doc->intSubset != NULL) {
|
||||
xmlAttributePtr attrDecl;
|
||||
xmlAttributePtr attrDecl = NULL;
|
||||
xmlNsPtr *nsList, *cur;
|
||||
xmlChar *ename;
|
||||
|
||||
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, node->name, name);
|
||||
if ((attrDecl == NULL) && (doc->extSubset != NULL))
|
||||
attrDecl = xmlGetDtdAttrDesc(doc->extSubset, node->name, name);
|
||||
|
||||
if ((attrDecl != NULL) && (attrDecl->prefix != NULL)) {
|
||||
/*
|
||||
* The DTD declaration only allows a prefix search
|
||||
*/
|
||||
ns = xmlSearchNs(doc, node, attrDecl->prefix);
|
||||
if ((ns != NULL) && (xmlStrEqual(ns->href, nameSpace)))
|
||||
return((xmlAttrPtr) attrDecl);
|
||||
nsList = xmlGetNsList(node->doc, node);
|
||||
if (nsList == NULL)
|
||||
return(NULL);
|
||||
if ((node->ns != NULL) && (node->ns->prefix != NULL)) {
|
||||
ename = xmlStrdup(node->ns->prefix);
|
||||
ename = xmlStrcat(ename, BAD_CAST ":");
|
||||
ename = xmlStrcat(ename, node->name);
|
||||
} else {
|
||||
ename = xmlStrdup(node->name);
|
||||
}
|
||||
if (ename == NULL) {
|
||||
xmlFree(nsList);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
cur = nsList;
|
||||
while (*cur != NULL) {
|
||||
if (xmlStrEqual((*cur)->href, nameSpace)) {
|
||||
attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, ename,
|
||||
name, (*cur)->prefix);
|
||||
if ((attrDecl == NULL) && (doc->extSubset != NULL))
|
||||
attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, ename,
|
||||
name, (*cur)->prefix);
|
||||
}
|
||||
cur++;
|
||||
}
|
||||
xmlFree(nsList);
|
||||
xmlFree(ename);
|
||||
return((xmlAttrPtr) attrDecl);
|
||||
}
|
||||
}
|
||||
return(NULL);
|
||||
|
Reference in New Issue
Block a user