aboutsummaryrefslogtreecommitdiffstats
path: root/valid.c
diff options
context:
space:
mode:
Diffstat (limited to 'valid.c')
-rw-r--r--valid.c277
1 files changed, 195 insertions, 82 deletions
diff --git a/valid.c b/valid.c
index 2510b8d6..594d3839 100644
--- a/valid.c
+++ b/valid.c
@@ -36,6 +36,11 @@ static xmlElementPtr xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name,
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
+#ifdef LIBXML_VALID_ENABLED
+static int
+xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type,
+ const xmlChar *value);
+#endif
/************************************************************************
* *
* Error handling routines *
@@ -2024,7 +2029,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
return(NULL);
}
if ((defaultValue != NULL) &&
- (!xmlValidateAttributeValue(type, defaultValue))) {
+ (!xmlValidateAttributeValueInternal(dtd->doc, type, defaultValue))) {
xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT,
"Attribute %s of %s: invalid default value\n",
elem, name, defaultValue);
@@ -2042,8 +2047,10 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
(dtd->doc->intSubset != NULL) &&
(dtd->doc->intSubset->attributes != NULL)) {
ret = xmlHashLookup3(dtd->doc->intSubset->attributes, name, ns, elem);
- if (ret != NULL)
+ if (ret != NULL) {
+ xmlFreeEnumeration(tree);
return(NULL);
+ }
}
/*
@@ -2057,6 +2064,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
if (table == NULL) {
xmlVErrMemory(ctxt,
"xmlAddAttributeDecl: Table creation failed!\n");
+ xmlFreeEnumeration(tree);
return(NULL);
}
@@ -2064,6 +2072,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,
ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));
if (ret == NULL) {
xmlVErrMemory(ctxt, "malloc failed");
+ xmlFreeEnumeration(tree);
return(NULL);
}
memset(ret, 0, sizeof(xmlAttribute));
@@ -3445,8 +3454,78 @@ xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) {
}
#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
@@ -3454,8 +3533,8 @@ xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) {
* returns 1 if valid or 0 otherwise
*/
-int
-xmlValidateNameValue(const xmlChar *value) {
+static int
+xmlValidateNameValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur;
int val, len;
@@ -3463,18 +3542,12 @@ xmlValidateNameValue(const xmlChar *value) {
cur = value;
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
- if (!IS_LETTER(val) && (val != '_') &&
- (val != ':')) {
+ if (!xmlIsDocNameStartChar(doc, 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))) {
+ while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
@@ -3485,7 +3558,22 @@ xmlValidateNameValue(const xmlChar *value) {
}
/**
- * xmlValidateNamesValue:
+ * xmlValidateNameValue:
+ * @value: an Name value
+ *
+ * Validate that the given value match Name production
+ *
+ * returns 1 if valid or 0 otherwise
+ */
+
+int
+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
@@ -3493,8 +3581,8 @@ xmlValidateNameValue(const xmlChar *value) {
* returns 1 if valid or 0 otherwise
*/
-int
-xmlValidateNamesValue(const xmlChar *value) {
+static int
+xmlValidateNamesValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur;
int val, len;
@@ -3502,19 +3590,13 @@ xmlValidateNamesValue(const xmlChar *value) {
cur = value;
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
-
- if (!IS_LETTER(val) && (val != '_') &&
- (val != ':')) {
+
+ if (!xmlIsDocNameStartChar(doc, 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))) {
+ while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
@@ -3526,18 +3608,13 @@ xmlValidateNamesValue(const xmlChar *value) {
cur += len;
}
- if (!IS_LETTER(val) && (val != '_') &&
- (val != ':')) {
+ if (!xmlIsDocNameStartChar(doc, 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))) {
+ while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
@@ -3549,18 +3626,33 @@ xmlValidateNamesValue(const xmlChar *value) {
}
/**
- * xmlValidateNmtokenValue:
+ * xmlValidateNamesValue:
+ * @value: an Names value
+ *
+ * Validate that the given value match Names production
+ *
+ * returns 1 if valid or 0 otherwise
+ */
+
+int
+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
*/
-int
-xmlValidateNmtokenValue(const xmlChar *value) {
+static int
+xmlValidateNmtokenValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur;
int val, len;
@@ -3568,19 +3660,13 @@ xmlValidateNmtokenValue(const xmlChar *value) {
cur = value;
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
-
- if (!IS_LETTER(val) && !IS_DIGIT(val) &&
- (val != '.') && (val != '-') &&
- (val != '_') && (val != ':') &&
- (!IS_COMBINING(val)) &&
- (!IS_EXTENDER(val)))
+
+ if (!xmlIsDocNameChar(doc, 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;
+ while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
@@ -3591,18 +3677,35 @@ xmlValidateNmtokenValue(const xmlChar *value) {
}
/**
- * xmlValidateNmtokensValue:
+ * xmlValidateNmtokenValue:
+ * @value: an Nmtoken value
+ *
+ * Validate that the given value match Nmtoken production
+ *
+ * [ VC: Name Token ]
+ *
+ * returns 1 if valid or 0 otherwise
+ */
+
+int
+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
*/
-int
-xmlValidateNmtokensValue(const xmlChar *value) {
+static int
+xmlValidateNmtokensValueInternal(xmlDocPtr doc, const xmlChar *value) {
const xmlChar *cur;
int val, len;
@@ -3610,24 +3713,16 @@ xmlValidateNmtokensValue(const xmlChar *value) {
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)))
+ if (!xmlIsDocNameChar(doc, val))
return(0);
- while ((IS_LETTER(val)) || (IS_DIGIT(val)) ||
- (val == '.') || (val == '-') ||
- (val == '_') || (val == ':') ||
- (IS_COMBINING(val)) ||
- (IS_EXTENDER(val))) {
+ while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
@@ -3640,18 +3735,13 @@ xmlValidateNmtokensValue(const xmlChar *value) {
}
if (val == 0) return(1);
- if (!IS_LETTER(val) && !IS_DIGIT(val) &&
- (val != '.') && (val != '-') &&
- (val != '_') && (val != ':') &&
- (!IS_COMBINING(val)) &&
- (!IS_EXTENDER(val)))
+ if (!xmlIsDocNameChar(doc, 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;
+
+ while (xmlIsDocNameChar(doc, val)) {
val = xmlStringCurrentChar(NULL, cur, &len);
cur += len;
}
@@ -3663,6 +3753,22 @@ xmlValidateNmtokensValue(const xmlChar *value) {
}
/**
+ * xmlValidateNmtokensValue:
+ * @value: an Nmtokens value
+ *
+ * Validate that the given value match Nmtokens production
+ *
+ * [ VC: Name Token ]
+ *
+ * returns 1 if valid or 0 otherwise
+ */
+
+int
+xmlValidateNmtokensValue(const xmlChar *value) {
+ return(xmlValidateNmtokensValueInternal(NULL, value));
+}
+
+/**
* xmlValidateNotationDecl:
* @ctxt: the validation context
* @doc: a document instance
@@ -3710,28 +3816,34 @@ xmlValidateNotationDecl(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc ATT
* returns 1 if valid or 0 otherwise
*/
-int
-xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) {
+static int
+xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type,
+ const xmlChar *value) {
switch (type) {
case XML_ATTRIBUTE_ENTITIES:
case XML_ATTRIBUTE_IDREFS:
- return(xmlValidateNamesValue(value));
+ return(xmlValidateNamesValueInternal(doc, value));
case XML_ATTRIBUTE_ENTITY:
case XML_ATTRIBUTE_IDREF:
case XML_ATTRIBUTE_ID:
case XML_ATTRIBUTE_NOTATION:
- return(xmlValidateNameValue(value));
+ return(xmlValidateNameValueInternal(doc, value));
case XML_ATTRIBUTE_NMTOKENS:
case XML_ATTRIBUTE_ENUMERATION:
- return(xmlValidateNmtokensValue(value));
+ return(xmlValidateNmtokensValueInternal(doc, value));
case XML_ATTRIBUTE_NMTOKEN:
- return(xmlValidateNmtokenValue(value));
+ return(xmlValidateNmtokenValueInternal(doc, value));
case XML_ATTRIBUTE_CDATA:
break;
}
return(1);
}
+int
+xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) {
+ return(xmlValidateAttributeValueInternal(NULL, type, value));
+}
+
/**
* xmlValidateAttributeValue2:
* @ctxt: the validation context
@@ -4047,11 +4159,12 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
int val;
CHECK_DTD;
if(attr == NULL) return(1);
-
+
/* Attribute Default Legal */
/* Enumeration */
if (attr->defaultValue != NULL) {
- val = xmlValidateAttributeValue(attr->atype, attr->defaultValue);
+ val = xmlValidateAttributeValueInternal(doc, attr->atype,
+ attr->defaultValue);
if (val == 0) {
xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_DEFAULT,
"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;
- val = xmlValidateAttributeValue(attrDecl->atype, value);
+ val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value);
if (val == 0) {
xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,
"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);
}
- val = xmlValidateAttributeValue(attrDecl->atype, value);
+ val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value);
if (val == 0) {
if (ns->prefix != NULL) {
xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT,