Bump to 3.4.11.2 and update changelog
[mikachu/openbox.git] / parser / parse.c
index 636b451..6db7ca7 100644 (file)
@@ -219,10 +219,12 @@ void parse_close(xmlDocPtr doc)
 void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
 {
     while (node) {
-        struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
+        if (node->name) {
+            struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
 
-        if (c)
-            c->func(i, doc, node, c->data);
+            if (c)
+                c->func(i, doc, node, c->data);
+        }
 
         node = node->next;
     }
@@ -231,7 +233,9 @@ void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
 gchar *parse_string(xmlDocPtr doc, xmlNodePtr node)
 {
     xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
-    gchar *s = g_strdup(c ? (gchar*)c : "");
+    gchar *s;
+    if (c) g_strstrip((char*)c);
+    s = g_strdup(c ? (gchar*)c : "");
     xmlFree(c);
     return s;
 }
@@ -239,7 +243,9 @@ gchar *parse_string(xmlDocPtr doc, xmlNodePtr node)
 gint parse_int(xmlDocPtr doc, xmlNodePtr node)
 {
     xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
-    gint i = c ? atoi((gchar*)c) : 0;
+    gint i;
+    if (c) g_strstrip((char*)c);
+    i = c ? atoi((gchar*)c) : 0;
     xmlFree(c);
     return i;
 }
@@ -248,6 +254,7 @@ gboolean parse_bool(xmlDocPtr doc, xmlNodePtr node)
 {
     xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
     gboolean b = FALSE;
+    if (c) g_strstrip((char*)c);
     if (c && !xmlStrcasecmp(c, (const xmlChar*) "true"))
         b = TRUE;
     else if (c && !xmlStrcasecmp(c, (const xmlChar*) "yes"))
@@ -262,6 +269,7 @@ gboolean parse_contains(const gchar *val, xmlDocPtr doc, xmlNodePtr node)
 {
     xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
     gboolean r;
+    if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */
     r = !xmlStrcasecmp(c, (const xmlChar*) val);
     xmlFree(c);
     return r;
@@ -282,6 +290,7 @@ gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value)
     xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
     gboolean r = FALSE;
     if (c) {
+        g_strstrip((char*)c); /* strip leading/trailing whitespace */
         if (!xmlStrcasecmp(c, (const xmlChar*) "true"))
             *value = TRUE, r = TRUE;
         else if (!xmlStrcasecmp(c, (const xmlChar*) "yes"))
@@ -304,6 +313,7 @@ gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value)
     xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
     gboolean r = FALSE;
     if (c) {
+        g_strstrip((char*)c); /* strip leading/trailing whitespace */
         *value = atoi((gchar*)c);
         r = TRUE;
     }
@@ -316,6 +326,7 @@ gboolean parse_attr_string(const gchar *name, xmlNodePtr node, gchar **value)
     xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
     gboolean r = FALSE;
     if (c) {
+        g_strstrip((char*)c); /* strip leading/trailing whitespace */
         *value = g_strdup((gchar*)c);
         r = TRUE;
     }
@@ -328,8 +339,10 @@ gboolean parse_attr_contains(const gchar *val, xmlNodePtr node,
 {
     xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
     gboolean r = FALSE;
-    if (c)
+    if (c) {
+        g_strstrip((char*)c);
         r = !xmlStrcasecmp(c, (const xmlChar*) val);
+    }
     xmlFree(c);
     return r;
 }
@@ -456,14 +469,17 @@ void parse_paths_shutdown(void)
 
 gchar *parse_expand_tilde(const gchar *f)
 {
-    gchar **spl;
     gchar *ret;
+    GRegex *regex;
 
     if (!f)
         return NULL;
-    spl = g_strsplit(f, "~", 0);
-    ret = g_strjoinv(g_get_home_dir(), spl);
-    g_strfreev(spl);
+
+    regex = g_regex_new("(?:^|(?<=[ \\t]))~(?:(?=[/ \\t])|$)",
+                        G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL);
+    ret = g_regex_replace_literal(regex, f, -1, 0, g_get_home_dir(), 0, NULL);
+    g_regex_unref(regex);
+
     return ret;
 }