]> git.tokkee.org Git - inkscape.git/commitdiff

Code

fix for #1483198 ("infectious namespaces")
authormental <mental@users.sourceforge.net>
Sun, 7 May 2006 03:57:22 +0000 (03:57 +0000)
committermental <mental@users.sourceforge.net>
Sun, 7 May 2006 03:57:22 +0000 (03:57 +0000)
ChangeLog
src/xml/repr-util.cpp

index b55477ca0e8cc8b4598b8f10c5ebdef29d77d643..9b49f39e370ee8329dc4319ab601ab18ecc1bd32 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-05-06  MenTaLguY  <mental@rydia.net>
+
+       * src/xml/repr-util.cpp:
+
+         fix for #1483198 ("infectious namespaces")
+
 2006-05-01  Jon A. Cruz  <jon@joncruz.org>
 
        * src/verbs.h, src/verbs.cpp, src/verbs-test.h:
index 75ae692af5c39ba2291ac47ee508f6488e180087..4d61c42c521abcc298644d74ea80db5ca916e961 100644 (file)
@@ -212,7 +212,6 @@ sp_xml_ns_auto_prefix(char const *uri)
 gchar const *
 sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested)
 {
-    SPXMLNs *iter;
     char const *prefix;
 
     if (!uri) return NULL;
@@ -223,32 +222,46 @@ sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested)
 
     GQuark const key = g_quark_from_string(uri);
     prefix = NULL;
-    for ( iter = namespaces ; iter ; iter = iter->next ) {
+    for ( SPXMLNs *iter=namespaces ; iter ; iter = iter->next ) {
         if ( iter->uri == key ) {
             prefix = g_quark_to_string(iter->prefix);
             break;
         }
     }
+
     if (!prefix) {
-        char const *new_prefix;
+        char *new_prefix;
         SPXMLNs *ns;
         if (suggested) {
-            new_prefix = suggested;
+            GQuark const prefix_key=g_quark_from_string(suggested);
+
+            SPXMLNs *found=namespaces;
+            while ( found && found->prefix != prefix_key ) {
+                found = found->next;
+            }
+
+            if (found) { // prefix already used?
+                new_prefix = sp_xml_ns_auto_prefix(uri);
+            } else { // safe to use suggested
+                new_prefix = g_strdup(suggested);
+            }
         } else {
             new_prefix = sp_xml_ns_auto_prefix(uri);
         }
+
         ns = g_new(SPXMLNs, 1);
-        if (ns) {
-            ns->uri = g_quark_from_string(uri);
-            ns->prefix = g_quark_from_string(new_prefix);
-            ns->next = namespaces;
-            namespaces = ns;
-            prefix = g_quark_to_string(ns->prefix);
-        }
-        if (!suggested) {
-            g_free((char *)new_prefix);
-        }
+        g_assert( ns != NULL );
+        ns->uri = g_quark_from_string(uri);
+        ns->prefix = g_quark_from_string(new_prefix);
+
+        g_free(new_prefix);
+
+        ns->next = namespaces;
+        namespaces = ns;
+
+        prefix = g_quark_to_string(ns->prefix);
     }
+
     return prefix;
 }