mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
Fixed SAX2 validation: grow of internal namespace list, appending of
* xmlschemas.c: Fixed SAX2 validation: grow of internal namespace list, appending of element character content. * xstc/xstc.py: Added "--sax" option for SAX2 validation.
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
Thu Jun 16 14:38:22 CEST 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
||||||
|
|
||||||
|
* xmlschemas.c: Fixed SAX2 validation: grow of internal
|
||||||
|
namespace list, appending of element character content.
|
||||||
|
* xstc/xstc.py: Added "--sax" option for SAX2 validation.
|
||||||
|
|
||||||
Wed Jun 15 15:34:52 CEST 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
Wed Jun 15 15:34:52 CEST 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
||||||
|
|
||||||
* xmlschemastypes.c: Added missing function descriptions.
|
* xmlschemastypes.c: Added missing function descriptions.
|
||||||
|
30
xmlschemas.c
30
xmlschemas.c
@@ -21942,8 +21942,7 @@ xmlSchemaVContentModelCallback(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt)
|
xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt)
|
||||||
{
|
{
|
||||||
vctxt->depth++;
|
|
||||||
vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt);
|
vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt);
|
||||||
if (vctxt->inode == NULL) {
|
if (vctxt->inode == NULL) {
|
||||||
VERROR_INT("xmlSchemaValidatorPushElem",
|
VERROR_INT("xmlSchemaValidatorPushElem",
|
||||||
@@ -21995,8 +21994,9 @@ xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
|
|||||||
if ((inode->typeDef == NULL) ||
|
if ((inode->typeDef == NULL) ||
|
||||||
(inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) {
|
(inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) {
|
||||||
/*
|
/*
|
||||||
* The type definition might be missing if the element was
|
* 1. the type definition might be missing if the element was
|
||||||
* error prone.
|
* error prone
|
||||||
|
* 2. it might be abstract.
|
||||||
*/
|
*/
|
||||||
goto end_elem;
|
goto end_elem;
|
||||||
}
|
}
|
||||||
@@ -22747,11 +22747,14 @@ xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt,
|
|||||||
* Concat the value.
|
* Concat the value.
|
||||||
*/
|
*/
|
||||||
if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
|
if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
|
||||||
vctxt->inode->value =
|
xmlChar *tmp;
|
||||||
BAD_CAST xmlStrncatNew(vctxt->inode->value, value, -1);
|
|
||||||
|
tmp = BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len);
|
||||||
|
xmlFree((xmlChar *) vctxt->inode->value);
|
||||||
|
vctxt->inode->value = tmp;
|
||||||
} else {
|
} else {
|
||||||
vctxt->inode->value =
|
vctxt->inode->value =
|
||||||
BAD_CAST xmlStrncatNew(vctxt->inode->value, value, -1);
|
BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len);
|
||||||
vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
|
vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22874,7 +22877,7 @@ type_validation:
|
|||||||
vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
|
vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
|
||||||
ret = XML_SCHEMAV_CVC_TYPE_2;
|
ret = XML_SCHEMAV_CVC_TYPE_2;
|
||||||
VERROR(ret, NULL,
|
VERROR(ret, NULL,
|
||||||
"The type definition is abstract");
|
"The type definition is abstract");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -22953,6 +22956,7 @@ root_found:
|
|||||||
|
|
||||||
if (nodeType == XML_ELEMENT_NODE) {
|
if (nodeType == XML_ELEMENT_NODE) {
|
||||||
|
|
||||||
|
vctxt->depth++;
|
||||||
if (xmlSchemaValidatorPushElem(vctxt) == -1) {
|
if (xmlSchemaValidatorPushElem(vctxt) == -1) {
|
||||||
VERROR_INT("xmlSchemaVReaderWalk",
|
VERROR_INT("xmlSchemaVReaderWalk",
|
||||||
"calling xmlSchemaValidatorPushElem()");
|
"calling xmlSchemaValidatorPushElem()");
|
||||||
@@ -23207,9 +23211,10 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
|
|||||||
* SAX VAL TODO: What to do with nb_defaulted?
|
* SAX VAL TODO: What to do with nb_defaulted?
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* Skip elements if inside a "skip" wildcard.
|
* Skip elements if inside a "skip" wildcard or invalid.
|
||||||
*/
|
*/
|
||||||
if ((vctxt->skipDepth != -1) && (vctxt->depth > vctxt->skipDepth))
|
vctxt->depth++;
|
||||||
|
if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
|
||||||
return;
|
return;
|
||||||
/*
|
/*
|
||||||
* Push the element.
|
* Push the element.
|
||||||
@@ -23252,7 +23257,7 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
|
|||||||
ielem->nsBindings =
|
ielem->nsBindings =
|
||||||
(const xmlChar **) xmlRealloc(
|
(const xmlChar **) xmlRealloc(
|
||||||
(void *) ielem->nsBindings,
|
(void *) ielem->nsBindings,
|
||||||
ielem->nbNsBindings * 2 * sizeof(const xmlChar *));
|
ielem->sizeNsBindings * 2 * sizeof(const xmlChar *));
|
||||||
if (ielem->nsBindings == NULL) {
|
if (ielem->nsBindings == NULL) {
|
||||||
xmlSchemaVErrMemory(vctxt,
|
xmlSchemaVErrMemory(vctxt,
|
||||||
"re-allocating namespace bindings for SAX validation",
|
"re-allocating namespace bindings for SAX validation",
|
||||||
@@ -23328,7 +23333,7 @@ xmlSchemaSAXHandleEndElementNs(void *ctx,
|
|||||||
int res;
|
int res;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip elements if inside a "skip" wildcard.
|
* Skip elements if inside a "skip" wildcard or if invalid.
|
||||||
*/
|
*/
|
||||||
if (vctxt->skipDepth != -1) {
|
if (vctxt->skipDepth != -1) {
|
||||||
if (vctxt->depth > vctxt->skipDepth) {
|
if (vctxt->depth > vctxt->skipDepth) {
|
||||||
@@ -23676,6 +23681,7 @@ xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt)
|
|||||||
/*
|
/*
|
||||||
* Init the node-info.
|
* Init the node-info.
|
||||||
*/
|
*/
|
||||||
|
vctxt->depth++;
|
||||||
if (xmlSchemaValidatorPushElem(vctxt) == -1)
|
if (xmlSchemaValidatorPushElem(vctxt) == -1)
|
||||||
goto internal_error;
|
goto internal_error;
|
||||||
ielem = vctxt->inode;
|
ielem = vctxt->inode;
|
||||||
|
97
xstc/xstc.py
97
xstc/xstc.py
@@ -82,6 +82,12 @@ opa.add_option("--debug", action="store_true",
|
|||||||
opa.add_option("--info", action="store_true",
|
opa.add_option("--info", action="store_true",
|
||||||
dest="info", default=False,
|
dest="info", default=False,
|
||||||
help="Displays info on the suite only. Does not run any test.")
|
help="Displays info on the suite only. Does not run any test.")
|
||||||
|
opa.add_option("--sax", action="store_true",
|
||||||
|
dest="validationSAX", default=False,
|
||||||
|
help="Use SAX2-driven validation.")
|
||||||
|
opa.add_option("--tn", action="store_true",
|
||||||
|
dest="displayTestName", default=False,
|
||||||
|
help="Display the test name in every case.")
|
||||||
|
|
||||||
(options, args) = opa.parse_args()
|
(options, args) = opa.parse_args()
|
||||||
|
|
||||||
@@ -312,6 +318,8 @@ class XSTCTestCase:
|
|||||||
|
|
||||||
##filePath = os.path.join(options.baseDir, self.fileName)
|
##filePath = os.path.join(options.baseDir, self.fileName)
|
||||||
# filePath = "%s/%s/%s/%s" % (options.baseDir, self.test_Folder, self.schema_Folder, self.schema_File)
|
# filePath = "%s/%s/%s/%s" % (options.baseDir, self.test_Folder, self.schema_Folder, self.schema_File)
|
||||||
|
if options.displayTestName:
|
||||||
|
sys.stdout.write("'%s'\n" % self.name)
|
||||||
try:
|
try:
|
||||||
self.validate()
|
self.validate()
|
||||||
except (Exception, libxml2.parserError, libxml2.treeError), e:
|
except (Exception, libxml2.parserError, libxml2.treeError), e:
|
||||||
@@ -387,52 +395,55 @@ class XSTCInstanceTest(XSTCTestCase):
|
|||||||
# TODO: Is this one necessary, or will an exception
|
# TODO: Is this one necessary, or will an exception
|
||||||
# be already raised?
|
# be already raised?
|
||||||
raise Exception("Could not create the instance parser context.")
|
raise Exception("Could not create the instance parser context.")
|
||||||
try:
|
if not options.validationSAX:
|
||||||
try:
|
try:
|
||||||
instance = parserCtxt.ctxtReadFile(filePath, None, libxml2.XML_PARSE_NOWARNING)
|
|
||||||
except:
|
|
||||||
# Suppress exceptions.
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
del parserCtxt
|
|
||||||
self.debugMsg("after loading instance")
|
|
||||||
|
|
||||||
if instance is None:
|
|
||||||
self.debugMsg("instance is None")
|
|
||||||
self.failCritical("Failed to parse the instance for unknown reasons.")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
#
|
|
||||||
# Validate the instance.
|
|
||||||
#
|
|
||||||
self.debugMsg("loading schema: %s" % self.group.schemaFileName)
|
|
||||||
schema = parseSchema(self.group.schemaFileName)
|
|
||||||
try:
|
try:
|
||||||
validationCtxt = schema.schemaNewValidCtxt()
|
instance = parserCtxt.ctxtReadFile(filePath, None, libxml2.XML_PARSE_NOWARNING)
|
||||||
#validationCtxt = libxml2.schemaNewValidCtxt(None)
|
except:
|
||||||
if (validationCtxt is None):
|
# Suppress exceptions.
|
||||||
self.failCritical("Could not create the validation context.")
|
pass
|
||||||
return
|
|
||||||
try:
|
|
||||||
self.debugMsg("validating instance")
|
|
||||||
instance_Err = validationCtxt.schemaValidateDoc(instance)
|
|
||||||
self.debugMsg("after instance validation")
|
|
||||||
self.debugMsg("instance-err: %d" % instance_Err)
|
|
||||||
if (instance_Err != 0 and self.val == 1) or (instance_Err == 0 and self.val == 0):
|
|
||||||
self.debugMsg("instance result is BAD")
|
|
||||||
if (instance_Err != 0):
|
|
||||||
self.fail(msgInstanceNotValidButShould)
|
|
||||||
else:
|
|
||||||
self.fail(msgInstanceValidButShouldNot)
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.debugMsg("instance result is OK")
|
|
||||||
finally:
|
|
||||||
del validationCtxt
|
|
||||||
finally:
|
|
||||||
del schema
|
|
||||||
finally:
|
finally:
|
||||||
|
del parserCtxt
|
||||||
|
self.debugMsg("after loading instance")
|
||||||
|
if instance is None:
|
||||||
|
self.debugMsg("instance is None")
|
||||||
|
self.failCritical("Failed to parse the instance for unknown reasons.")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
#
|
||||||
|
# Validate the instance.
|
||||||
|
#
|
||||||
|
self.debugMsg("loading schema: %s" % self.group.schemaFileName)
|
||||||
|
schema = parseSchema(self.group.schemaFileName)
|
||||||
|
try:
|
||||||
|
validationCtxt = schema.schemaNewValidCtxt()
|
||||||
|
#validationCtxt = libxml2.schemaNewValidCtxt(None)
|
||||||
|
if (validationCtxt is None):
|
||||||
|
self.failCritical("Could not create the validation context.")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.debugMsg("validating instance")
|
||||||
|
if options.validationSAX:
|
||||||
|
instance_Err = validationCtxt.schemaValidateFile(filePath, 0)
|
||||||
|
else:
|
||||||
|
instance_Err = validationCtxt.schemaValidateDoc(instance)
|
||||||
|
self.debugMsg("after instance validation")
|
||||||
|
self.debugMsg("instance-err: %d" % instance_Err)
|
||||||
|
if (instance_Err != 0 and self.val == 1) or (instance_Err == 0 and self.val == 0):
|
||||||
|
self.debugMsg("instance result is BAD")
|
||||||
|
if (instance_Err != 0):
|
||||||
|
self.fail(msgInstanceNotValidButShould)
|
||||||
|
else:
|
||||||
|
self.fail(msgInstanceValidButShouldNot)
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.debugMsg("instance result is OK")
|
||||||
|
finally:
|
||||||
|
del validationCtxt
|
||||||
|
finally:
|
||||||
|
del schema
|
||||||
|
finally:
|
||||||
|
if instance is not None:
|
||||||
instance.freeDoc()
|
instance.freeDoc()
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user