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

patch from Julien Charbon to simplify the processing of xmlSetProp()

* include/libxml/xmlerror.h tree.c: patch from Julien Charbon
  to simplify the processing of xmlSetProp()
Daniel

svn path=/trunk/; revision=3694
This commit is contained in:
Daniel Veillard
2008-02-15 08:33:21 +00:00
parent 8e1a46d526
commit 6f8611fdb4
3 changed files with 23 additions and 8 deletions

View File

@@ -1,3 +1,8 @@
Fri Feb 15 09:32:11 CET 2008 Daniel Veillard <daniel@veillard.com>
* include/libxml/xmlerror.h tree.c: patch from Julien Charbon
to simplify the processing of xmlSetProp()
Fri Feb 15 08:45:32 CET 2008 Daniel Veillard <daniel@veillard.com> Fri Feb 15 08:45:32 CET 2008 Daniel Veillard <daniel@veillard.com>
* config.h.in configure.in encoding.c: patch from Roumen Petrov * config.h.in configure.in encoding.c: patch from Roumen Petrov

View File

@@ -398,6 +398,7 @@ typedef enum {
XML_TREE_INVALID_HEX = 1300, XML_TREE_INVALID_HEX = 1300,
XML_TREE_INVALID_DEC, /* 1301 */ XML_TREE_INVALID_DEC, /* 1301 */
XML_TREE_UNTERMINATED_ENTITY, /* 1302 */ XML_TREE_UNTERMINATED_ENTITY, /* 1302 */
XML_TREE_NOT_UTF8, /* 1303 */
XML_SAVE_NOT_UTF8 = 1400, XML_SAVE_NOT_UTF8 = 1400,
XML_SAVE_CHAR_INVALID, /* 1401 */ XML_SAVE_CHAR_INVALID, /* 1401 */
XML_SAVE_NO_DOCTYPE, /* 1402 */ XML_SAVE_NO_DOCTYPE, /* 1402 */

25
tree.c
View File

@@ -92,6 +92,9 @@ xmlTreeErr(int code, xmlNodePtr node, const char *extra)
case XML_TREE_UNTERMINATED_ENTITY: case XML_TREE_UNTERMINATED_ENTITY:
msg = "unterminated entity reference %15s\n"; msg = "unterminated entity reference %15s\n";
break; break;
case XML_TREE_NOT_UTF8:
msg = "string is not in UTF-8\n";
break;
default: default:
msg = "unexpected error number\n"; msg = "unexpected error number\n";
} }
@@ -1814,11 +1817,15 @@ xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns,
cur->name = name; cur->name = name;
if (value != NULL) { if (value != NULL) {
xmlChar *buffer;
xmlNodePtr tmp; xmlNodePtr tmp;
buffer = xmlEncodeEntitiesReentrant(doc, value); if(!xmlCheckUTF8(value)) {
cur->children = xmlStringGetNodeList(doc, buffer); xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) doc,
NULL);
if (doc != NULL)
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
}
cur->children = xmlNewDocText(doc, value);
cur->last = NULL; cur->last = NULL;
tmp = cur->children; tmp = cur->children;
while (tmp != NULL) { while (tmp != NULL) {
@@ -1827,7 +1834,6 @@ xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns,
cur->last = tmp; cur->last = tmp;
tmp = tmp->next; tmp = tmp->next;
} }
xmlFree(buffer);
} }
/* /*
@@ -6466,11 +6472,15 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name,
prop->last = NULL; prop->last = NULL;
prop->ns = ns; prop->ns = ns;
if (value != NULL) { if (value != NULL) {
xmlChar *buffer;
xmlNodePtr tmp; xmlNodePtr tmp;
buffer = xmlEncodeEntitiesReentrant(node->doc, value); if(!xmlCheckUTF8(value)) {
prop->children = xmlStringGetNodeList(node->doc, buffer); xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) node->doc,
NULL);
if (node->doc != NULL)
node->doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
}
prop->children = xmlNewDocText(node->doc, value);
prop->last = NULL; prop->last = NULL;
tmp = prop->children; tmp = prop->children;
while (tmp != NULL) { while (tmp != NULL) {
@@ -6479,7 +6489,6 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name,
prop->last = tmp; prop->last = tmp;
tmp = tmp->next; tmp = tmp->next;
} }
xmlFree(buffer);
} }
if (prop->atype == XML_ATTRIBUTE_ID) if (prop->atype == XML_ATTRIBUTE_ID)
xmlAddID(NULL, node->doc, value, prop); xmlAddID(NULL, node->doc, value, prop);