summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2014-05-27 10:44:05 +0200
committerGravatar Martin Szulecki2014-05-27 10:44:05 +0200
commit63abebfba51a96e6862cd84e8a768b2c1f6ec834 (patch)
treeed7d18de9edc5ca61e21e286e0c1b8b47bc16e2e
parent06e7233b6ba0aa19b68b993420b90de277e10c9b (diff)
downloadlibplist-63abebfba51a96e6862cd84e8a768b2c1f6ec834.tar.gz
libplist-63abebfba51a96e6862cd84e8a768b2c1f6ec834.tar.bz2
xplist: Fix keys not being output correctly if converted to XML entities
-rw-r--r--src/xplist.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/xplist.c b/src/xplist.c
index eaa2468..96539a6 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -199,7 +199,7 @@ static void node_to_xml(node_t* node, void *xml_struct)
case PLIST_STRING:
tag = XPLIST_STRING;
- val = strdup(node_data->strval);
+ val = strdup((char*) node_data->strval);
break;
case PLIST_KEY:
@@ -257,7 +257,7 @@ static void node_to_xml(node_t* node, void *xml_struct)
{
xmlNodeAddContent(xstruct->xml, BAD_CAST("\t"));
}
- if (node_data->type == PLIST_STRING) {
+ if (node_data->type == PLIST_STRING || node_data->type == PLIST_KEY) {
/* make sure we convert the following predefined xml entities */
/* < = &lt; > = &gt; ' = &apos; " = &quot; & = &amp; */
child_node = xmlNewTextChild(xstruct->xml, NULL, tag, BAD_CAST(val));
@@ -458,9 +458,15 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
if (!xmlStrcmp(node->name, XPLIST_KEY))
{
xmlChar *strval = xmlNodeGetContent(node);
- data->strval = strdup((char *) strval);
- data->type = PLIST_KEY;
- data->length = strlen(data->strval);
+ len = strlen((char *) strval);
+ type = xmlDetectCharEncoding(strval, len);
+
+ if (XML_CHAR_ENCODING_UTF8 == type || XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type)
+ {
+ data->strval = strdup((char *) strval);
+ data->type = PLIST_KEY;
+ data->length = strlen(data->strval);
+ }
xmlFree(strval);
continue;
}