1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-13 13:17:36 +03:00

more progresses against the official regression tests small cleanup for

* runxmlconf.c: more progresses against the official regression tests
* runsuite.c: small cleanup for non-leak reports
* include/libxml/tree.h: parsing flags and other properties are
  now added to the document node, this is generally useful and
  allow to make Name and NmToken validations based on the parser
  flags, more specifically the 5th edition of XML or not
* HTMLparser.c tree.c: small side effects for the previous changes
* parser.c SAX2.c valid.c: the bulk of teh changes are here,
  the parser and validation behaviour can be affected, parsing
  flags need to be copied, lot of changes. Also fixing various
  validation problems in the regression tests.
Daniel

svn path=/trunk/; revision=3762
This commit is contained in:
Daniel Veillard 2008-07-31 19:54:59 +00:00
parent 373345764b
commit ae0765b681
9 changed files with 463 additions and 196 deletions

View File

@ -1,3 +1,17 @@
Thu Jul 31 21:49:45 CEST 2008 Daniel Veillard <daniel@veillard.com>
* runxmlconf.c: more progresses against the official regression tests
* runsuite.c: small cleanup for non-leak reports
* include/libxml/tree.h: parsing flags and other properties are
now added to the document node, this is generally useful and
allow to make Name and NmToken validations based on the parser
flags, more specifically the 5th edition of XML or not
* HTMLparser.c tree.c: small side effects for the previous changes
* parser.c SAX2.c valid.c: the bulk of teh changes are here,
the parser and validation behaviour can be affected, parsing
flags need to be copied, lot of changes. Also fixing various
validation problems in the regression tests.
Thu Jul 31 10:15:53 CEST 2008 Daniel Veillard <daniel@veillard.com> Thu Jul 31 10:15:53 CEST 2008 Daniel Veillard <daniel@veillard.com>
* runxmlconf.c: added a skipped list, insert rmt-ns10-035 * runxmlconf.c: added a skipped list, insert rmt-ns10-035

View File

@ -2143,6 +2143,7 @@ htmlNewDocNoDtD(const xmlChar *URI, const xmlChar *ExternalID) {
cur->refs = NULL; cur->refs = NULL;
cur->_private = NULL; cur->_private = NULL;
cur->charset = XML_CHAR_ENCODING_UTF8; cur->charset = XML_CHAR_ENCODING_UTF8;
cur->properties = XML_DOC_HTML | XML_DOC_USERBUILT;
if ((ExternalID != NULL) || if ((ExternalID != NULL) ||
(URI != NULL)) (URI != NULL))
xmlCreateIntSubset(cur, BAD_CAST "html", ExternalID, URI); xmlCreateIntSubset(cur, BAD_CAST "html", ExternalID, URI);

6
SAX2.c
View File

@ -957,6 +957,8 @@ xmlSAX2StartDocument(void *ctx)
#ifdef LIBXML_HTML_ENABLED #ifdef LIBXML_HTML_ENABLED
if (ctxt->myDoc == NULL) if (ctxt->myDoc == NULL)
ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL); ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
ctxt->myDoc->properties = XML_DOC_HTML;
ctxt->myDoc->parseFlags = ctxt->options;
if (ctxt->myDoc == NULL) { if (ctxt->myDoc == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument"); xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
return; return;
@ -972,6 +974,10 @@ xmlSAX2StartDocument(void *ctx)
} else { } else {
doc = ctxt->myDoc = xmlNewDoc(ctxt->version); doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
if (doc != NULL) { if (doc != NULL) {
doc->properties = 0;
if (ctxt->options & XML_PARSE_OLD10)
doc->properties |= XML_DOC_OLD10;
doc->parseFlags = ctxt->options;
if (ctxt->encoding != NULL) if (ctxt->encoding != NULL)
doc->encoding = xmlStrdup(ctxt->encoding); doc->encoding = xmlStrdup(ctxt->encoding);
else else

View File

@ -482,6 +482,23 @@ struct _xmlNode {
#define XML_GET_LINE(n) \ #define XML_GET_LINE(n) \
(xmlGetLineNo(n)) (xmlGetLineNo(n))
/**
* xmlDocProperty
*
* Set of properties of the document as found by the parser
* Some of them are linked to similary named xmlParserOption
*/
typedef enum {
XML_DOC_WELLFORMED = 1<<0, /* document is XML well formed */
XML_DOC_NSVALID = 1<<1, /* document is Namespace valid */
XML_DOC_OLD10 = 1<<2, /* parsed with old XML-1.0 parser */
XML_DOC_DTDVALID = 1<<3, /* DTD validation was successful */
XML_DOC_XINCLUDE = 1<<4, /* XInclude substitution was done */
XML_DOC_USERBUILT = 1<<5, /* Document was built using the API
and not by parsing an instance */
XML_DOC_INTERNAL = 1<<6, /* built for internal processing */
XML_DOC_HTML = 1<<7 /* parsed or built HTML document */
} xmlDocProperties;
/** /**
* xmlDoc: * xmlDoc:
@ -521,6 +538,10 @@ struct _xmlDoc {
actually an xmlCharEncoding */ actually an xmlCharEncoding */
struct _xmlDict *dict; /* dict used to allocate names or NULL */ struct _xmlDict *dict; /* dict used to allocate names or NULL */
void *psvi; /* for type/PSVI informations */ void *psvi; /* for type/PSVI informations */
int parseFlags; /* set of xmlParserOption used to parse the
document */
int properties; /* set of xmlDocProperties for this document
set at the end of parsing */
}; };

109
parser.c
View File

@ -448,7 +448,7 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
*/ */
static void static void
xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error, xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1) const char *msg, const xmlChar *str1, const xmlChar *str2)
{ {
xmlStructuredErrorFunc schannel = NULL; xmlStructuredErrorFunc schannel = NULL;
@ -464,8 +464,8 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
ctxt->vctxt.error, ctxt->vctxt.userData, ctxt->vctxt.error, ctxt->vctxt.userData,
ctxt, NULL, XML_FROM_DTD, error, ctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, (const char *) str1, XML_ERR_ERROR, NULL, 0, (const char *) str1,
NULL, NULL, 0, 0, (const char *) str2, NULL, 0, 0,
msg, (const char *) str1); msg, (const char *) str1, (const char *) str2);
if (ctxt != NULL) { if (ctxt != NULL) {
ctxt->valid = 0; ctxt->valid = 0;
} }
@ -889,7 +889,7 @@ typedef xmlDefAttrs *xmlDefAttrsPtr;
struct _xmlDefAttrs { struct _xmlDefAttrs {
int nbAttrs; /* number of defaulted attributes on that element */ int nbAttrs; /* number of defaulted attributes on that element */
int maxAttrs; /* the size of the array */ int maxAttrs; /* the size of the array */
const xmlChar *values[4]; /* array of localname/prefix/values */ const xmlChar *values[5]; /* array of localname/prefix/values/external */
}; };
/** /**
@ -943,7 +943,7 @@ xmlAttrNormalizeSpace(const xmlChar *src, xmlChar *dst)
* is needed. * is needed.
*/ */
static const xmlChar * static const xmlChar *
xmlAttrNormalizeSpace2(xmlParserCtxtPtr ctxt, const xmlChar *src, int *len) xmlAttrNormalizeSpace2(xmlParserCtxtPtr ctxt, xmlChar *src, int *len)
{ {
int i; int i;
int remove_head = 0; int remove_head = 0;
@ -984,7 +984,8 @@ xmlAttrNormalizeSpace2(xmlParserCtxtPtr ctxt, const xmlChar *src, int *len)
return(ret); return(ret);
} else if (remove_head) { } else if (remove_head) {
*len -= remove_head; *len -= remove_head;
return(src + remove_head); memmove(src, src + remove_head, 1 + *len);
return(src);
} }
return(NULL); return(NULL);
} }
@ -1041,7 +1042,7 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt,
defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix); defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix);
if (defaults == NULL) { if (defaults == NULL) {
defaults = (xmlDefAttrsPtr) xmlMalloc(sizeof(xmlDefAttrs) + defaults = (xmlDefAttrsPtr) xmlMalloc(sizeof(xmlDefAttrs) +
(4 * 4) * sizeof(const xmlChar *)); (4 * 5) * sizeof(const xmlChar *));
if (defaults == NULL) if (defaults == NULL)
goto mem_error; goto mem_error;
defaults->nbAttrs = 0; defaults->nbAttrs = 0;
@ -1055,7 +1056,7 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt,
xmlDefAttrsPtr temp; xmlDefAttrsPtr temp;
temp = (xmlDefAttrsPtr) xmlRealloc(defaults, sizeof(xmlDefAttrs) + temp = (xmlDefAttrsPtr) xmlRealloc(defaults, sizeof(xmlDefAttrs) +
(2 * defaults->maxAttrs * 4) * sizeof(const xmlChar *)); (2 * defaults->maxAttrs * 5) * sizeof(const xmlChar *));
if (temp == NULL) if (temp == NULL)
goto mem_error; goto mem_error;
defaults = temp; defaults = temp;
@ -1080,13 +1081,17 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt,
prefix = xmlDictLookup(ctxt->dict, fullattr, len); prefix = xmlDictLookup(ctxt->dict, fullattr, len);
} }
defaults->values[4 * defaults->nbAttrs] = name; defaults->values[5 * defaults->nbAttrs] = name;
defaults->values[4 * defaults->nbAttrs + 1] = prefix; defaults->values[5 * defaults->nbAttrs + 1] = prefix;
/* intern the string and precompute the end */ /* intern the string and precompute the end */
len = xmlStrlen(value); len = xmlStrlen(value);
value = xmlDictLookup(ctxt->dict, value, len); value = xmlDictLookup(ctxt->dict, value, len);
defaults->values[4 * defaults->nbAttrs + 2] = value; defaults->values[5 * defaults->nbAttrs + 2] = value;
defaults->values[4 * defaults->nbAttrs + 3] = value + len; defaults->values[5 * defaults->nbAttrs + 3] = value + len;
if (ctxt->external)
defaults->values[5 * defaults->nbAttrs + 4] = BAD_CAST "external";
else
defaults->values[5 * defaults->nbAttrs + 4] = NULL;
defaults->nbAttrs++; defaults->nbAttrs++;
return; return;
@ -2264,7 +2269,7 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) { if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) {
xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY, xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
"PEReference: %%%s; not found\n", "PEReference: %%%s; not found\n",
name); name, NULL);
} else } else
xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
"PEReference: %%%s; not found\n", "PEReference: %%%s; not found\n",
@ -4947,6 +4952,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
xmlErrMemory(ctxt, "New Doc failed"); xmlErrMemory(ctxt, "New Doc failed");
return; return;
} }
ctxt->myDoc->properties = XML_DOC_INTERNAL;
} }
if (ctxt->myDoc->intSubset == NULL) if (ctxt->myDoc->intSubset == NULL)
ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc, ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
@ -5019,6 +5025,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
xmlErrMemory(ctxt, "New Doc failed"); xmlErrMemory(ctxt, "New Doc failed");
return; return;
} }
ctxt->myDoc->properties = XML_DOC_INTERNAL;
} }
if (ctxt->myDoc->intSubset == NULL) if (ctxt->myDoc->intSubset == NULL)
@ -5519,7 +5526,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) {
if ((ctxt->validate) && (ctxt->input->id != inputchk)) { if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
"Element content declaration doesn't start and stop in the same entity\n", "Element content declaration doesn't start and stop in the same entity\n",
NULL); NULL, NULL);
} }
NEXT; NEXT;
ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA); ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA);
@ -5577,7 +5584,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) {
if ((ctxt->validate) && (ctxt->input->id != inputchk)) { if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
"Element content declaration doesn't start and stop in the same entity\n", "Element content declaration doesn't start and stop in the same entity\n",
NULL); NULL, NULL);
} }
SKIP(2); SKIP(2);
} else { } else {
@ -5809,7 +5816,7 @@ xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk) {
if ((ctxt->validate) && (ctxt->input->id != inputchk)) { if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
"Element content declaration doesn't start and stop in the same entity\n", "Element content declaration doesn't start and stop in the same entity\n",
NULL); NULL, NULL);
} }
NEXT; NEXT;
if (RAW == '?') { if (RAW == '?') {
@ -6362,6 +6369,11 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
} }
if (ctxt->myDoc == NULL) { if (ctxt->myDoc == NULL) {
ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0");
if (ctxt->myDoc == NULL) {
xmlErrMemory(ctxt, "New Doc failed");
return;
}
ctxt->myDoc->properties = XML_DOC_INTERNAL;
} }
if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL)) if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL))
xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID); xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID);
@ -7994,7 +8006,13 @@ xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) {
xmlNsErr(ctxt, XML_NS_ERR_QNAME, xmlNsErr(ctxt, XML_NS_ERR_QNAME,
"Failed to parse QName '%s:'\n", p, NULL, NULL); "Failed to parse QName '%s:'\n", p, NULL, NULL);
tmp = xmlBuildQName(BAD_CAST "", p, NULL, 0); l = xmlParseNmtoken(ctxt);
if (l == NULL)
tmp = xmlBuildQName(BAD_CAST "", p, NULL, 0);
else {
tmp = xmlBuildQName(l, p, NULL, 0);
xmlFree((char *)l);
}
p = xmlDictLookup(ctxt->dict, tmp, -1); p = xmlDictLookup(ctxt->dict, tmp, -1);
if (tmp != NULL) xmlFree(tmp); if (tmp != NULL) xmlFree(tmp);
*prefix = NULL; *prefix = NULL;
@ -8302,7 +8320,7 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt,
const xmlChar *val2; const xmlChar *val2;
val2 = xmlAttrNormalizeSpace2(ctxt, val, len); val2 = xmlAttrNormalizeSpace2(ctxt, val, len);
if (val2 != NULL) { if ((val2 != NULL) && (val2 != val)) {
xmlFree(val); xmlFree(val);
val = (xmlChar *) val2; val = (xmlChar *) val2;
} }
@ -8642,8 +8660,8 @@ failed:
defaults = xmlHashLookup2(ctxt->attsDefault, localname, prefix); defaults = xmlHashLookup2(ctxt->attsDefault, localname, prefix);
if (defaults != NULL) { if (defaults != NULL) {
for (i = 0;i < defaults->nbAttrs;i++) { for (i = 0;i < defaults->nbAttrs;i++) {
attname = defaults->values[4 * i]; attname = defaults->values[5 * i];
aprefix = defaults->values[4 * i + 1]; aprefix = defaults->values[5 * i + 1];
/* /*
* special work for namespaces defaulted defs * special work for namespaces defaulted defs
@ -8658,9 +8676,9 @@ failed:
if (j <= nbNs) continue; if (j <= nbNs) continue;
nsname = xmlGetNamespace(ctxt, NULL); nsname = xmlGetNamespace(ctxt, NULL);
if (nsname != defaults->values[4 * i + 2]) { if (nsname != defaults->values[5 * i + 2]) {
if (nsPush(ctxt, NULL, if (nsPush(ctxt, NULL,
defaults->values[4 * i + 2]) > 0) defaults->values[5 * i + 2]) > 0)
nbNs++; nbNs++;
} }
} else if (aprefix == ctxt->str_xmlns) { } else if (aprefix == ctxt->str_xmlns) {
@ -8675,7 +8693,7 @@ failed:
nsname = xmlGetNamespace(ctxt, attname); nsname = xmlGetNamespace(ctxt, attname);
if (nsname != defaults->values[2]) { if (nsname != defaults->values[2]) {
if (nsPush(ctxt, attname, if (nsPush(ctxt, attname,
defaults->values[4 * i + 2]) > 0) defaults->values[5 * i + 2]) > 0)
nbNs++; nbNs++;
} }
} else { } else {
@ -8701,8 +8719,14 @@ failed:
atts[nbatts++] = NULL; atts[nbatts++] = NULL;
else else
atts[nbatts++] = xmlGetNamespace(ctxt, aprefix); atts[nbatts++] = xmlGetNamespace(ctxt, aprefix);
atts[nbatts++] = defaults->values[4 * i + 2]; atts[nbatts++] = defaults->values[5 * i + 2];
atts[nbatts++] = defaults->values[4 * i + 3]; atts[nbatts++] = defaults->values[5 * i + 3];
if ((ctxt->standalone == 1) &&
(defaults->values[5 * i + 4] != NULL)) {
xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,
"standalone: attribute %s on %s defaulted from external subset\n",
attname, localname);
}
nbdef++; nbdef++;
} }
} }
@ -9876,6 +9900,15 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
ctxt->myDoc = NULL; ctxt->myDoc = NULL;
} }
if ((ctxt->wellFormed) && (ctxt->myDoc != NULL)) {
ctxt->myDoc->properties |= XML_DOC_WELLFORMED;
if (ctxt->valid)
ctxt->myDoc->properties |= XML_DOC_DTDVALID;
if (ctxt->nsWellFormed)
ctxt->myDoc->properties |= XML_DOC_NSVALID;
if (ctxt->options & XML_PARSE_OLD10)
ctxt->myDoc->properties |= XML_DOC_OLD10;
}
if (! ctxt->wellFormed) { if (! ctxt->wellFormed) {
ctxt->valid = 0; ctxt->valid = 0;
return(-1); return(-1);
@ -11537,6 +11570,11 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input,
*/ */
ctxt->inSubset = 2; ctxt->inSubset = 2;
ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0");
if (ctxt->myDoc == NULL) {
xmlErrMemory(ctxt, "New Doc failed");
return(NULL);
}
ctxt->myDoc->properties = XML_DOC_INTERNAL;
ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none",
BAD_CAST "none", BAD_CAST "none"); BAD_CAST "none", BAD_CAST "none");
@ -11670,6 +11708,13 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID,
*/ */
ctxt->inSubset = 2; ctxt->inSubset = 2;
ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0");
if (ctxt->myDoc == NULL) {
xmlErrMemory(ctxt, "New Doc failed");
if (sax != NULL) ctxt->sax = NULL;
xmlFreeParserCtxt(ctxt);
return(NULL);
}
ctxt->myDoc->properties = XML_DOC_INTERNAL;
ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none",
ExternalID, SystemID); ExternalID, SystemID);
xmlParseExternalSubset(ctxt, ExternalID, SystemID); xmlParseExternalSubset(ctxt, ExternalID, SystemID);
@ -11795,6 +11840,7 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
return(-1); return(-1);
} }
newDoc->properties = XML_DOC_INTERNAL;
if (ctx->myDoc->dict) { if (ctx->myDoc->dict) {
newDoc->dict = ctx->myDoc->dict; newDoc->dict = ctx->myDoc->dict;
xmlDictReference(newDoc->dict); xmlDictReference(newDoc->dict);
@ -12015,6 +12061,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
return(XML_ERR_INTERNAL_ERROR); return(XML_ERR_INTERNAL_ERROR);
} }
newDoc->properties = XML_DOC_INTERNAL;
newDoc->intSubset = doc->intSubset; newDoc->intSubset = doc->intSubset;
newDoc->extSubset = doc->extSubset; newDoc->extSubset = doc->extSubset;
newDoc->dict = doc->dict; newDoc->dict = doc->dict;
@ -12246,6 +12293,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
return(XML_ERR_INTERNAL_ERROR); return(XML_ERR_INTERNAL_ERROR);
} }
newDoc->properties = XML_DOC_INTERNAL;
newDoc->dict = ctxt->dict; newDoc->dict = ctxt->dict;
xmlDictReference(newDoc->dict); xmlDictReference(newDoc->dict);
ctxt->myDoc = newDoc; ctxt->myDoc = newDoc;
@ -12610,6 +12658,7 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax,
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
return(-1); return(-1);
} }
newDoc->properties = XML_DOC_INTERNAL;
if ((doc != NULL) && (doc->dict != NULL)) { if ((doc != NULL) && (doc->dict != NULL)) {
xmlDictFree(ctxt->dict); xmlDictFree(ctxt->dict);
ctxt->dict = doc->dict; ctxt->dict = doc->dict;
@ -13800,32 +13849,38 @@ xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int options, const char *encodi
if (options & XML_PARSE_RECOVER) { if (options & XML_PARSE_RECOVER) {
ctxt->recovery = 1; ctxt->recovery = 1;
options -= XML_PARSE_RECOVER; options -= XML_PARSE_RECOVER;
ctxt->options |= XML_PARSE_RECOVER;
} else } else
ctxt->recovery = 0; ctxt->recovery = 0;
if (options & XML_PARSE_DTDLOAD) { if (options & XML_PARSE_DTDLOAD) {
ctxt->loadsubset = XML_DETECT_IDS; ctxt->loadsubset = XML_DETECT_IDS;
options -= XML_PARSE_DTDLOAD; options -= XML_PARSE_DTDLOAD;
ctxt->options |= XML_PARSE_DTDLOAD;
} else } else
ctxt->loadsubset = 0; ctxt->loadsubset = 0;
if (options & XML_PARSE_DTDATTR) { if (options & XML_PARSE_DTDATTR) {
ctxt->loadsubset |= XML_COMPLETE_ATTRS; ctxt->loadsubset |= XML_COMPLETE_ATTRS;
options -= XML_PARSE_DTDATTR; options -= XML_PARSE_DTDATTR;
ctxt->options |= XML_PARSE_DTDATTR;
} }
if (options & XML_PARSE_NOENT) { if (options & XML_PARSE_NOENT) {
ctxt->replaceEntities = 1; ctxt->replaceEntities = 1;
/* ctxt->loadsubset |= XML_DETECT_IDS; */ /* ctxt->loadsubset |= XML_DETECT_IDS; */
options -= XML_PARSE_NOENT; options -= XML_PARSE_NOENT;
ctxt->options |= XML_PARSE_NOENT;
} else } else
ctxt->replaceEntities = 0; ctxt->replaceEntities = 0;
if (options & XML_PARSE_PEDANTIC) { if (options & XML_PARSE_PEDANTIC) {
ctxt->pedantic = 1; ctxt->pedantic = 1;
options -= XML_PARSE_PEDANTIC; options -= XML_PARSE_PEDANTIC;
ctxt->options |= XML_PARSE_PEDANTIC;
} else } else
ctxt->pedantic = 0; ctxt->pedantic = 0;
if (options & XML_PARSE_NOBLANKS) { if (options & XML_PARSE_NOBLANKS) {
ctxt->keepBlanks = 0; ctxt->keepBlanks = 0;
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace; ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
options -= XML_PARSE_NOBLANKS; options -= XML_PARSE_NOBLANKS;
ctxt->options |= XML_PARSE_NOBLANKS;
} else } else
ctxt->keepBlanks = 1; ctxt->keepBlanks = 1;
if (options & XML_PARSE_DTDVALID) { if (options & XML_PARSE_DTDVALID) {
@ -13835,6 +13890,7 @@ xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int options, const char *encodi
if (options & XML_PARSE_NOERROR) if (options & XML_PARSE_NOERROR)
ctxt->vctxt.error = NULL; ctxt->vctxt.error = NULL;
options -= XML_PARSE_DTDVALID; options -= XML_PARSE_DTDVALID;
ctxt->options |= XML_PARSE_DTDVALID;
} else } else
ctxt->validate = 0; ctxt->validate = 0;
if (options & XML_PARSE_NOWARNING) { if (options & XML_PARSE_NOWARNING) {
@ -13854,17 +13910,20 @@ xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int options, const char *encodi
ctxt->sax->endElementNs = NULL; ctxt->sax->endElementNs = NULL;
ctxt->sax->initialized = 1; ctxt->sax->initialized = 1;
options -= XML_PARSE_SAX1; options -= XML_PARSE_SAX1;
ctxt->options |= XML_PARSE_SAX1;
} }
#endif /* LIBXML_SAX1_ENABLED */ #endif /* LIBXML_SAX1_ENABLED */
if (options & XML_PARSE_NODICT) { if (options & XML_PARSE_NODICT) {
ctxt->dictNames = 0; ctxt->dictNames = 0;
options -= XML_PARSE_NODICT; options -= XML_PARSE_NODICT;
ctxt->options |= XML_PARSE_NODICT;
} else { } else {
ctxt->dictNames = 1; ctxt->dictNames = 1;
} }
if (options & XML_PARSE_NOCDATA) { if (options & XML_PARSE_NOCDATA) {
ctxt->sax->cdataBlock = NULL; ctxt->sax->cdataBlock = NULL;
options -= XML_PARSE_NOCDATA; options -= XML_PARSE_NOCDATA;
ctxt->options |= XML_PARSE_NOCDATA;
} }
if (options & XML_PARSE_NSCLEAN) { if (options & XML_PARSE_NSCLEAN) {
ctxt->options |= XML_PARSE_NSCLEAN; ctxt->options |= XML_PARSE_NSCLEAN;

View File

@ -358,7 +358,7 @@ done:
if (rng != NULL) if (rng != NULL)
xmlRelaxNGFree(rng); xmlRelaxNGFree(rng);
xmlResetLastError(); xmlResetLastError();
if ((memt != xmlMemUsed()) && (extraMemoryFromResolver == 0)) { if ((memt < xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
test_log("Validation of tests starting line %ld leaked %d\n", test_log("Validation of tests starting line %ld leaked %d\n",
xmlGetLineNo(cur), xmlMemUsed() - memt); xmlGetLineNo(cur), xmlMemUsed() - memt);
nb_leaks++; nb_leaks++;

View File

@ -92,49 +92,13 @@ static int nb_skipped = 0;
static int nb_tests = 0; static int nb_tests = 0;
static int nb_errors = 0; static int nb_errors = 0;
static int nb_leaks = 0; static int nb_leaks = 0;
static int extraMemoryFromResolver = 0;
static int
fatalError(void) {
fprintf(stderr, "Exitting tests on fatal error\n");
exit(1);
}
/*
* that's needed to implement <resource>
*/
#define MAX_ENTITIES 20
static char *testEntitiesName[MAX_ENTITIES];
static char *testEntitiesValue[MAX_ENTITIES];
static int nb_entities = 0;
static void resetEntities(void) {
int i;
for (i = 0;i < nb_entities;i++) {
if (testEntitiesName[i] != NULL)
xmlFree(testEntitiesName[i]);
if (testEntitiesValue[i] != NULL)
xmlFree(testEntitiesValue[i]);
}
nb_entities = 0;
}
static int addEntity(char *name, char *content) {
if (nb_entities >= MAX_ENTITIES) {
fprintf(stderr, "Too many entities defined\n");
return(-1);
}
testEntitiesName[nb_entities] = name;
testEntitiesValue[nb_entities] = content;
nb_entities++;
return(0);
}
/* /*
* We need to trap calls to the resolver to not account memory for the catalog * We need to trap calls to the resolver to not account memory for the catalog
* and not rely on any external resources. * and not rely on any external resources.
*/ */
static xmlParserInputPtr static xmlParserInputPtr
testExternalEntityLoader(const char *URL, const char *ID, testExternalEntityLoader(const char *URL, const char *ID ATTRIBUTE_UNUSED,
xmlParserCtxtPtr ctxt) { xmlParserCtxtPtr ctxt) {
xmlParserInputPtr ret; xmlParserInputPtr ret;
@ -149,6 +113,8 @@ testExternalEntityLoader(const char *URL, const char *ID,
*/ */
static char testErrors[32769]; static char testErrors[32769];
static int testErrorsSize = 0; static int testErrorsSize = 0;
static int nbError = 0;
static int nbFatal = 0;
static void test_log(const char *msg, ...) { static void test_log(const char *msg, ...) {
va_list args; va_list args;
@ -168,17 +134,19 @@ static void test_log(const char *msg, ...) {
} }
static void static void
testErrorHandler(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { testErrorHandler(void *userData ATTRIBUTE_UNUSED, xmlErrorPtr error) {
va_list args;
int res; int res;
if (testErrorsSize >= 32768) if (testErrorsSize >= 32768)
return; return;
va_start(args, msg); res = snprintf(&testErrors[testErrorsSize],
res = vsnprintf(&testErrors[testErrorsSize],
32768 - testErrorsSize, 32768 - testErrorsSize,
msg, args); "%s:%d: %s\n", (error->file ? error->file : "entity"),
va_end(args); error->line, error->message);
if (error->level == XML_ERR_FATAL)
nbFatal++;
else if (error->level == XML_ERR_ERROR)
nbError++;
if (testErrorsSize + res >= 32768) { if (testErrorsSize + res >= 32768) {
/* buffer is full */ /* buffer is full */
testErrorsSize = 32768; testErrorsSize = 32768;
@ -210,7 +178,7 @@ initializeLibxml2(void) {
*/ */
if (ctxtXPath->cache != NULL) if (ctxtXPath->cache != NULL)
xmlXPathContextSetCache(ctxtXPath, 0, -1, 0); xmlXPathContextSetCache(ctxtXPath, 0, -1, 0);
xmlSetGenericErrorFunc(NULL, testErrorHandler); xmlSetStructuredErrorFunc(NULL, testErrorHandler);
} }
/************************************************************************ /************************************************************************
@ -219,6 +187,68 @@ initializeLibxml2(void) {
* * * *
************************************************************************/ ************************************************************************/
static int
xmlconfTestInvalid(const char *id, const char *filename, int options) {
xmlDocPtr doc;
xmlParserCtxtPtr ctxt;
int ret = 1;
ctxt = xmlNewParserCtxt();
if (ctxt == NULL) {
test_log("test %s : %s out of memory\n",
id, filename);
return(0);
}
doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
if (doc == NULL) {
test_log("test %s : %s invalid document turned not well-formed too\n",
id, filename);
} else {
/* invalidity should be reported both in the context and in the document */
if ((ctxt->valid != 0) || (doc->properties & XML_DOC_DTDVALID)) {
test_log("test %s : %s failed to detect invalid document\n",
id, filename);
nb_errors++;
ret = 0;
}
xmlFreeDoc(doc);
}
xmlFreeParserCtxt(ctxt);
return(ret);
}
static int
xmlconfTestValid(const char *id, const char *filename, int options) {
xmlDocPtr doc;
xmlParserCtxtPtr ctxt;
int ret = 1;
ctxt = xmlNewParserCtxt();
if (ctxt == NULL) {
test_log("test %s : %s out of memory\n",
id, filename);
return(0);
}
doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
if (doc == NULL) {
test_log("test %s : %s failed to parse a valid document\n",
id, filename);
nb_errors++;
ret = 0;
} else {
/* validity should be reported both in the context and in the document */
if ((ctxt->valid == 0) || ((doc->properties & XML_DOC_DTDVALID) == 0)) {
test_log("test %s : %s failed to validate a valid document\n",
id, filename);
nb_errors++;
ret = 0;
}
xmlFreeDoc(doc);
}
xmlFreeParserCtxt(ctxt);
return(ret);
}
static int static int
xmlconfTestNotNSWF(const char *id, const char *filename, int options) { xmlconfTestNotNSWF(const char *id, const char *filename, int options) {
xmlDocPtr doc; xmlDocPtr doc;
@ -272,6 +302,7 @@ xmlconfTestItem(xmlDocPtr doc, xmlNodePtr cur) {
xmlChar *base = NULL; xmlChar *base = NULL;
xmlChar *id = NULL; xmlChar *id = NULL;
xmlChar *rec = NULL; xmlChar *rec = NULL;
xmlChar *version = NULL;
xmlChar *entities = NULL; xmlChar *entities = NULL;
xmlChar *edition = NULL; xmlChar *edition = NULL;
int options = 0; int options = 0;
@ -280,6 +311,8 @@ xmlconfTestItem(xmlDocPtr doc, xmlNodePtr cur) {
int i; int i;
testErrorsSize = 0; testErrors[0] = 0; testErrorsSize = 0; testErrors[0] = 0;
nbError = 0;
nbFatal = 0;
id = xmlGetProp(cur, BAD_CAST "ID"); id = xmlGetProp(cur, BAD_CAST "ID");
if (id == NULL) { if (id == NULL) {
test_log("test missing ID, line %ld\n", xmlGetLineNo(cur)); test_log("test missing ID, line %ld\n", xmlGetLineNo(cur));
@ -311,6 +344,8 @@ xmlconfTestItem(xmlDocPtr doc, xmlNodePtr cur) {
goto error; goto error;
} }
version = xmlGetProp(cur, BAD_CAST "VERSION");
entities = xmlGetProp(cur, BAD_CAST "ENTITIES"); entities = xmlGetProp(cur, BAD_CAST "ENTITIES");
if (!xmlStrEqual(entities, BAD_CAST "none")) { if (!xmlStrEqual(entities, BAD_CAST "none")) {
options |= XML_PARSE_DTDLOAD; options |= XML_PARSE_DTDLOAD;
@ -322,13 +357,19 @@ xmlconfTestItem(xmlDocPtr doc, xmlNodePtr cur) {
(xmlStrEqual(rec, BAD_CAST "XML1.0-errata2e")) || (xmlStrEqual(rec, BAD_CAST "XML1.0-errata2e")) ||
(xmlStrEqual(rec, BAD_CAST "XML1.0-errata3e")) || (xmlStrEqual(rec, BAD_CAST "XML1.0-errata3e")) ||
(xmlStrEqual(rec, BAD_CAST "XML1.0-errata4e"))) { (xmlStrEqual(rec, BAD_CAST "XML1.0-errata4e"))) {
if ((version != NULL) && (!xmlStrEqual(version, BAD_CAST "1.0"))) {
test_log("Skipping test %s for %s\n", (char *) id,
(char *) version);
ret = 0;
nb_skipped++;
goto error;
}
ret = 1; ret = 1;
} else if ((xmlStrEqual(rec, BAD_CAST "NS1.0")) || } else if ((xmlStrEqual(rec, BAD_CAST "NS1.0")) ||
(xmlStrEqual(rec, BAD_CAST "NS1.0-errata1e"))) { (xmlStrEqual(rec, BAD_CAST "NS1.0-errata1e"))) {
ret = 1; ret = 1;
nstest = 1; nstest = 1;
} else { } else {
testErrorsSize = 0; testErrors[0] = 0;
test_log("Skipping test %s for REC %s\n", (char *) id, (char *) rec); test_log("Skipping test %s for REC %s\n", (char *) id, (char *) rec);
ret = 0; ret = 0;
nb_skipped++; nb_skipped++;
@ -353,8 +394,16 @@ xmlconfTestItem(xmlDocPtr doc, xmlNodePtr cur) {
else else
xmlconfTestNotNSWF((char *) id, (char *) filename, options); xmlconfTestNotNSWF((char *) id, (char *) filename, options);
} else if (xmlStrEqual(type, BAD_CAST "valid")) { } else if (xmlStrEqual(type, BAD_CAST "valid")) {
options |= XML_PARSE_DTDVALID;
xmlconfTestValid((char *) id, (char *) filename, options);
} else if (xmlStrEqual(type, BAD_CAST "invalid")) { } else if (xmlStrEqual(type, BAD_CAST "invalid")) {
options |= XML_PARSE_DTDVALID;
xmlconfTestInvalid((char *) id, (char *) filename, options);
} else if (xmlStrEqual(type, BAD_CAST "error")) { } else if (xmlStrEqual(type, BAD_CAST "error")) {
test_log("Skipping error test %s \n", (char *) id);
ret = 0;
nb_skipped++;
goto error;
} else { } else {
test_log("test %s unknown TYPE value %s\n", (char *) id, (char *)type); test_log("test %s unknown TYPE value %s\n", (char *) id, (char *)type);
ret = -1; ret = -1;
@ -381,6 +430,8 @@ error:
xmlFree(entities); xmlFree(entities);
if (edition != NULL) if (edition != NULL)
xmlFree(edition); xmlFree(edition);
if (version != NULL)
xmlFree(version);
if (filename != NULL) if (filename != NULL)
xmlFree(filename); xmlFree(filename);
if (uri != NULL) if (uri != NULL)

4
tree.c
View File

@ -1148,11 +1148,13 @@ xmlNewDoc(const xmlChar *version) {
if (cur->version == NULL) { if (cur->version == NULL) {
xmlTreeErrMemory("building doc"); xmlTreeErrMemory("building doc");
xmlFree(cur); xmlFree(cur);
return(NULL); return(NULL);
} }
cur->standalone = -1; cur->standalone = -1;
cur->compression = -1; /* not initialized */ cur->compression = -1; /* not initialized */
cur->doc = cur; cur->doc = cur;
cur->parseFlags = 0;
cur->properties = XML_DOC_USERBUILT;
/* /*
* The in memory encoding is always UTF8 * The in memory encoding is always UTF8
* This field will never change and would * This field will never change and would

361
valid.c
View File

@ -36,6 +36,11 @@ static xmlElementPtr xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name,
"Unimplemented block at %s:%d\n", \ "Unimplemented block at %s:%d\n", \
__FILE__, __LINE__); __FILE__, __LINE__);
#ifdef LIBXML_VALID_ENABLED
static int
xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type,
const xmlChar *value);
#endif
/************************************************************************ /************************************************************************
* * * *
* Error handling routines * * Error handling routines *
@ -2024,7 +2029,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
return(NULL); return(NULL);
} }
if ((defaultValue != NULL) && if ((defaultValue != NULL) &&
(!xmlValidateAttributeValue(type, defaultValue))) { (!xmlValidateAttributeValueInternal(dtd->doc, type, defaultValue))) {
xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT, xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT,
"Attribute %s of %s: invalid default value\n", "Attribute %s of %s: invalid default value\n",
elem, name, defaultValue); elem, name, defaultValue);
@ -2042,8 +2047,10 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
(dtd->doc->intSubset != NULL) && (dtd->doc->intSubset != NULL) &&
(dtd->doc->intSubset->attributes != NULL)) { (dtd->doc->intSubset->attributes != NULL)) {
ret = xmlHashLookup3(dtd->doc->intSubset->attributes, name, ns, elem); ret = xmlHashLookup3(dtd->doc->intSubset->attributes, name, ns, elem);
if (ret != NULL) if (ret != NULL) {
xmlFreeEnumeration(tree);
return(NULL); return(NULL);
}
} }
/* /*
@ -2057,6 +2064,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
if (table == NULL) { if (table == NULL) {
xmlVErrMemory(ctxt, xmlVErrMemory(ctxt,
"xmlAddAttributeDecl: Table creation failed!\n"); "xmlAddAttributeDecl: Table creation failed!\n");
xmlFreeEnumeration(tree);
return(NULL); return(NULL);
} }
@ -2064,6 +2072,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute)); ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));
if (ret == NULL) { if (ret == NULL) {
xmlVErrMemory(ctxt, "malloc failed"); xmlVErrMemory(ctxt, "malloc failed");
xmlFreeEnumeration(tree);
return(NULL); return(NULL);
} }
memset(ret, 0, sizeof(xmlAttribute)); memset(ret, 0, sizeof(xmlAttribute));
@ -3445,6 +3454,109 @@ xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) {
} }
#ifdef LIBXML_VALID_ENABLED #ifdef LIBXML_VALID_ENABLED
static int
xmlIsDocNameStartChar(xmlDocPtr doc, int c) {
if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) {
/*
* Use the new checks of production [4] [4a] amd [5] of the
* Update 5 of XML-1.0
*/
if (((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) ||
(c == '_') || (c == ':') ||
((c >= 0xC0) && (c <= 0xD6)) ||
((c >= 0xD8) && (c <= 0xF6)) ||
((c >= 0xF8) && (c <= 0x2FF)) ||
((c >= 0x370) && (c <= 0x37D)) ||
((c >= 0x37F) && (c <= 0x1FFF)) ||
((c >= 0x200C) && (c <= 0x200D)) ||
((c >= 0x2070) && (c <= 0x218F)) ||
((c >= 0x2C00) && (c <= 0x2FEF)) ||
((c >= 0x3001) && (c <= 0xD7FF)) ||
((c >= 0xF900) && (c <= 0xFDCF)) ||
((c >= 0xFDF0) && (c <= 0xFFFD)) ||
((c >= 0x10000) && (c <= 0xEFFFF)))
return(1);
} else {
if (IS_LETTER(c) || (c == '_') || (c == ':'))
return(1);
}
return(0);
}
static int
xmlIsDocNameChar(xmlDocPtr doc, int c) {
if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) {
/*
* Use the new checks of production [4] [4a] amd [5] of the
* Update 5 of XML-1.0
*/
if (((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) ||
((c >= '0') && (c <= '9')) || /* !start */
(c == '_') || (c == ':') ||
(c == '-') || (c == '.') || (c == 0xB7) || /* !start */
((c >= 0xC0) && (c <= 0xD6)) ||
((c >= 0xD8) && (c <= 0xF6)) ||
((c >= 0xF8) && (c <= 0x2FF)) ||
((c >= 0x300) && (c <= 0x36F)) || /* !start */
((c >= 0x370) && (c <= 0x37D)) ||
((c >= 0x37F) && (c <= 0x1FFF)) ||
((c >= 0x200C) && (c <= 0x200D)) ||
((c >= 0x203F) && (c <= 0x2040)) || /* !start */
((c >= 0x2070) && (c <= 0x218F)) ||
((c >= 0x2C00) && (c <= 0x2FEF)) ||
((c >= 0x3001) && (c <= 0xD7FF)) ||
((c >= 0xF900) && (c <= 0xFDCF)) ||
((c >= 0xFDF0) && (c <= 0xFFFD)) ||
((c >= 0x10000) && (c <= 0xEFFFF)))
return(1);
} else {
if ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
(c == '.') || (c == '-') ||
(c == '_') || (c == ':') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c)))
return(1);
}
return(0);
}
/**
* xmlValidateNameValue:
* @doc: pointer to the document or NULL
* @value: an Name value
*
* Validate that the given value match Name production
*
* returns 1 if valid or 0 otherwise
*/
static int
xmlValidateNameValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur;
int val, len;
if (value == NULL) return(0);
cur = value;
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
if (!xmlIsDocNameStartChar(doc, val))
return(0);
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
if (val != 0) return(0);
return(1);
}
/** /**
* xmlValidateNameValue: * xmlValidateNameValue:
* @value: an Name value * @value: an Name value
@ -3456,6 +3568,21 @@ xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) {
int int
xmlValidateNameValue(const xmlChar *value) { xmlValidateNameValue(const xmlChar *value) {
return(xmlValidateNameValueInternal(NULL, value));
}
/**
* xmlValidateNamesValueInternal:
* @doc: pointer to the document or NULL
* @value: an Names value
*
* Validate that the given value match Names production
*
* returns 1 if valid or 0 otherwise
*/
static int
xmlValidateNamesValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur; const xmlChar *cur;
int val, len; int val, len;
@ -3463,22 +3590,36 @@ xmlValidateNameValue(const xmlChar *value) {
cur = value; cur = value;
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
if (!IS_LETTER(val) && (val != '_') &&
(val != ':')) { if (!xmlIsDocNameStartChar(doc, val))
return(0); return(0);
}
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
while ((IS_LETTER(val)) || (IS_DIGIT(val)) || while (xmlIsDocNameChar(doc, val)) {
(val == '.') || (val == '-') ||
(val == '_') || (val == ':') ||
(IS_COMBINING(val)) ||
(IS_EXTENDER(val))) {
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
} }
/* Should not test IS_BLANK(val) here -- see erratum E20*/
while (val == 0x20) {
while (val == 0x20) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
if (!xmlIsDocNameStartChar(doc, val))
return(0);
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
}
if (val != 0) return(0); if (val != 0) return(0);
return(1); return(1);
@ -3495,6 +3636,23 @@ xmlValidateNameValue(const xmlChar *value) {
int int
xmlValidateNamesValue(const xmlChar *value) { xmlValidateNamesValue(const xmlChar *value) {
return(xmlValidateNamesValueInternal(NULL, value));
}
/**
* xmlValidateNmtokenValueInternal:
* @doc: pointer to the document or NULL
* @value: an Nmtoken value
*
* Validate that the given value match Nmtoken production
*
* [ VC: Name Token ]
*
* returns 1 if valid or 0 otherwise
*/
static int
xmlValidateNmtokenValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur; const xmlChar *cur;
int val, len; int val, len;
@ -3502,47 +3660,17 @@ xmlValidateNamesValue(const xmlChar *value) {
cur = value; cur = value;
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
if (!IS_LETTER(val) && (val != '_') && if (!xmlIsDocNameChar(doc, val))
(val != ':')) {
return(0); return(0);
}
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
while ((IS_LETTER(val)) || (IS_DIGIT(val)) || while (xmlIsDocNameChar(doc, val)) {
(val == '.') || (val == '-') ||
(val == '_') || (val == ':') ||
(IS_COMBINING(val)) ||
(IS_EXTENDER(val))) {
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
} }
/* Should not test IS_BLANK(val) here -- see erratum E20*/
while (val == 0x20) {
while (val == 0x20) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
if (!IS_LETTER(val) && (val != '_') &&
(val != ':')) {
return(0);
}
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
while ((IS_LETTER(val)) || (IS_DIGIT(val)) ||
(val == '.') || (val == '-') ||
(val == '_') || (val == ':') ||
(IS_COMBINING(val)) ||
(IS_EXTENDER(val))) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
}
if (val != 0) return(0); if (val != 0) return(0);
return(1); return(1);
@ -3555,12 +3683,29 @@ xmlValidateNamesValue(const xmlChar *value) {
* Validate that the given value match Nmtoken production * Validate that the given value match Nmtoken production
* *
* [ VC: Name Token ] * [ VC: Name Token ]
* *
* returns 1 if valid or 0 otherwise * returns 1 if valid or 0 otherwise
*/ */
int int
xmlValidateNmtokenValue(const xmlChar *value) { xmlValidateNmtokenValue(const xmlChar *value) {
return(xmlValidateNmtokenValueInternal(NULL, value));
}
/**
* xmlValidateNmtokensValueInternal:
* @doc: pointer to the document or NULL
* @value: an Nmtokens value
*
* Validate that the given value match Nmtokens production
*
* [ VC: Name Token ]
*
* returns 1 if valid or 0 otherwise
*/
static int
xmlValidateNmtokensValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur; const xmlChar *cur;
int val, len; int val, len;
@ -3568,23 +3713,40 @@ xmlValidateNmtokenValue(const xmlChar *value) {
cur = value; cur = value;
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
if (!IS_LETTER(val) && !IS_DIGIT(val) &&
(val != '.') && (val != '-') &&
(val != '_') && (val != ':') &&
(!IS_COMBINING(val)) &&
(!IS_EXTENDER(val)))
return(0);
while ((IS_LETTER(val)) || (IS_DIGIT(val)) || while (IS_BLANK(val)) {
(val == '.') || (val == '-') ||
(val == '_') || (val == ':') ||
(IS_COMBINING(val)) ||
(IS_EXTENDER(val))) {
val = xmlStringCurrentChar(NULL, cur, &len); val = xmlStringCurrentChar(NULL, cur, &len);
cur += len; cur += len;
} }
if (!xmlIsDocNameChar(doc, val))
return(0);
while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
/* Should not test IS_BLANK(val) here -- see erratum E20*/
while (val == 0x20) {
while (val == 0x20) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
if (val == 0) return(1);
if (!xmlIsDocNameChar(doc, val))
return(0);
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
}
if (val != 0) return(0); if (val != 0) return(0);
return(1); return(1);
@ -3597,69 +3759,13 @@ xmlValidateNmtokenValue(const xmlChar *value) {
* Validate that the given value match Nmtokens production * Validate that the given value match Nmtokens production
* *
* [ VC: Name Token ] * [ VC: Name Token ]
* *
* returns 1 if valid or 0 otherwise * returns 1 if valid or 0 otherwise
*/ */
int int
xmlValidateNmtokensValue(const xmlChar *value) { xmlValidateNmtokensValue(const xmlChar *value) {
const xmlChar *cur; return(xmlValidateNmtokensValueInternal(NULL, value));
int val, len;
if (value == NULL) return(0);
cur = value;
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
while (IS_BLANK(val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
if (!IS_LETTER(val) && !IS_DIGIT(val) &&
(val != '.') && (val != '-') &&
(val != '_') && (val != ':') &&
(!IS_COMBINING(val)) &&
(!IS_EXTENDER(val)))
return(0);
while ((IS_LETTER(val)) || (IS_DIGIT(val)) ||
(val == '.') || (val == '-') ||
(val == '_') || (val == ':') ||
(IS_COMBINING(val)) ||
(IS_EXTENDER(val))) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
/* Should not test IS_BLANK(val) here -- see erratum E20*/
while (val == 0x20) {
while (val == 0x20) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
if (val == 0) return(1);
if (!IS_LETTER(val) && !IS_DIGIT(val) &&
(val != '.') && (val != '-') &&
(val != '_') && (val != ':') &&
(!IS_COMBINING(val)) &&
(!IS_EXTENDER(val)))
return(0);
while ((IS_LETTER(val)) || (IS_DIGIT(val)) ||
(val == '.') || (val == '-') ||
(val == '_') || (val == ':') ||
(IS_COMBINING(val)) ||
(IS_EXTENDER(val))) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
}
if (val != 0) return(0);
return(1);
} }
/** /**
@ -3710,28 +3816,34 @@ xmlValidateNotationDecl(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc ATT
* returns 1 if valid or 0 otherwise * returns 1 if valid or 0 otherwise
*/ */
int static int
xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) { xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type,
const xmlChar *value) {
switch (type) { switch (type) {
case XML_ATTRIBUTE_ENTITIES: case XML_ATTRIBUTE_ENTITIES:
case XML_ATTRIBUTE_IDREFS: case XML_ATTRIBUTE_IDREFS:
return(xmlValidateNamesValue(value)); return(xmlValidateNamesValueInternal(doc, value));
case XML_ATTRIBUTE_ENTITY: case XML_ATTRIBUTE_ENTITY:
case XML_ATTRIBUTE_IDREF: case XML_ATTRIBUTE_IDREF:
case XML_ATTRIBUTE_ID: case XML_ATTRIBUTE_ID:
case XML_ATTRIBUTE_NOTATION: case XML_ATTRIBUTE_NOTATION:
return(xmlValidateNameValue(value)); return(xmlValidateNameValueInternal(doc, value));
case XML_ATTRIBUTE_NMTOKENS: case XML_ATTRIBUTE_NMTOKENS:
case XML_ATTRIBUTE_ENUMERATION: case XML_ATTRIBUTE_ENUMERATION:
return(xmlValidateNmtokensValue(value)); return(xmlValidateNmtokensValueInternal(doc, value));
case XML_ATTRIBUTE_NMTOKEN: case XML_ATTRIBUTE_NMTOKEN:
return(xmlValidateNmtokenValue(value)); return(xmlValidateNmtokenValueInternal(doc, value));
case XML_ATTRIBUTE_CDATA: case XML_ATTRIBUTE_CDATA:
break; break;
} }
return(1); return(1);
} }
int
xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) {
return(xmlValidateAttributeValueInternal(NULL, type, value));
}
/** /**
* xmlValidateAttributeValue2: * xmlValidateAttributeValue2:
* @ctxt: the validation context * @ctxt: the validation context
@ -4047,11 +4159,12 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
int val; int val;
CHECK_DTD; CHECK_DTD;
if(attr == NULL) return(1); if(attr == NULL) return(1);
/* Attribute Default Legal */ /* Attribute Default Legal */
/* Enumeration */ /* Enumeration */
if (attr->defaultValue != NULL) { if (attr->defaultValue != NULL) {
val = xmlValidateAttributeValue(attr->atype, attr->defaultValue); val = xmlValidateAttributeValueInternal(doc, attr->atype,
attr->defaultValue);
if (val == 0) { if (val == 0) {
xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_DEFAULT, xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_DEFAULT,
"Syntax of default value for attribute %s of %s is not valid\n", "Syntax of default value for attribute %s of %s is not valid\n",
@ -4332,7 +4445,7 @@ xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
} }
attr->atype = attrDecl->atype; attr->atype = attrDecl->atype;
val = xmlValidateAttributeValue(attrDecl->atype, value); val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value);
if (val == 0) { if (val == 0) {
xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE, xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,
"Syntax of value for attribute %s of %s is not valid\n", "Syntax of value for attribute %s of %s is not valid\n",
@ -4517,7 +4630,7 @@ xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) {
return(0); return(0);
} }
val = xmlValidateAttributeValue(attrDecl->atype, value); val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value);
if (val == 0) { if (val == 0) {
if (ns->prefix != NULL) { if (ns->prefix != NULL) {
xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT, xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT,