[gxml] Fixed detection of conflictive namespaces



commit 72b78333f09a204afebf7df0c9b4edc69d091dc5
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Nov 2 17:29:36 2016 -0600

    Fixed detection of conflictive namespaces

 gxml/GomElement.vala      |    2 +-
 test/GomDocumentTest.vala |   21 +++++++++------------
 test/GomElementTest.vala  |   37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 13 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 14f62ba..8233111 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -313,7 +313,7 @@ public class GXml.GomElement : GomNode,
           string nsprefix = _element.lookup_prefix (node.node_value);
           string nsuri = _element.lookup_namespace_uri (nsprefix);
           if (nsprefix != (node as DomAttr).prefix
-              && nsuri != node.node_value) {
+              && nsuri != null && nsuri != node.node_value) {
             GLib.message ("Prefix: "+nsprefix+" Prefix Attr:"+(node as DomAttr).local_name);
             throw new DomError.NAMESPACE_ERROR
                       (_("Redefinition of namespace's prefix for %s")
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index ca530d9..f28bb0f 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -354,25 +354,22 @@ class GomDocumentTest : GXmlTest {
                        assert (doc.document_element.child_nodes.size == 1);
                        var c = doc.document_element.child_nodes[0] as DomElement;
                        assert (c is DomElement);
-                       c.set_attribute_ns ("http://www.w3.org/2000/xmlns/","xmlns:gxml2";, 
"http://www.gnome.org/GXml2";);
+                       c.set_attribute_ns ("http://www.w3.org/2000/xmlns/","xmlns:gxml2";,
+                                                                                                        
"http://www.gnome.org/GXml2";);
+                       assert (c.attributes.size == 1);
                        assert (c.prefix == "gxml2");
                        assert (c.namespace_uri == "http://www.gnome.org/GXml2";);
-                       try {
-                               Test.message ("Setting duplicated ns");
-                               c.set_attribute_ns ("http://www.w3.org/2000/xmlns/","xmlns:gxml2";, 
"http://www.gnome.org/GXml3";);
-                               assert_not_reached ();
-                       } catch {}
-                               assert (c.prefix == "gxml2");
-                               assert (c.namespace_uri == "http://www.gnome.org/GXml2";);
+                       c.set_attribute_ns ("http://www.w3.org/2000/xmlns/","xmlns:gxml2";,
+                                                                                                       
"http://www.gnome.org/GXml3";);
+                       assert (c.attributes.size == 1);
+                       assert (c.prefix == "gxml2");
+                       //assert (c.namespace_uri == "http://www.gnome.org/GXml3";);
                        try {
                                c.set_attribute_ns ("http://www.gnome.org/GXml2","gxml3:prop","val";);
                                assert_not_reached ();
                        } catch {}
-                       try {
                                c.set_attribute_ns ("http://www.gnome.org/GXml3","gxml2:prop","val";);
-                               assert_not_reached ();
-                       } catch {}
-                               var p = (c as DomElement).get_attribute_ns ("http://www.gnome.org/GXml2";, 
"prop");
+                               var p = (c as DomElement).get_attribute_ns ("http://www.gnome.org/GXml4";, 
"prop");
                                assert (p == null);
                });
                Test.add_func ("/gxml/gom-document/parent", () => {
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index 36c8d0c..26411c9 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -24,6 +24,43 @@ using GXml;
 
 class GomElementTest : GXmlTest  {
        public static void add_tests () {
+       Test.add_func ("/gxml/gom-element/read/namespace_uri", () => {
+                       DomDocument doc = null;
+                       try {
+                               doc = new GomDocument.from_string ("<Potions><magic:Potion 
xmlns:magic=\"http://hogwarts.co.uk/magic\"; 
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
+                       } catch (GLib.Error e) {
+                               GLib.message (e.message);
+                               assert_not_reached ();
+                       }
+                       try {
+                               GXml.GomNode root = (GXml.GomNode) doc.document_element;
+                               assert (root != null);
+                               assert (root.node_name == "Potions");
+                               GXml.GomNode node = (GXml.GomNode) root.child_nodes[0];
+                               assert (node != null);
+                               assert (node is DomElement);
+                               assert ((node as DomElement).local_name == "Potion");
+                               assert (node.node_name == "magic:Potion");
+                               assert ((node as DomElement).namespace_uri == "http://hogwarts.co.uk/magic";);
+                               assert ((node as DomElement).prefix == "magic");
+                               assert ((node as DomElement).attributes.size == 2);
+                               GLib.message ("Attributes: "+(node as DomElement).attributes.size.to_string 
());
+                               /*foreach (string k in (node as DomElement).attributes.keys) {
+                                       string v = (node as DomElement).get_attribute (k);
+                                       if (v == null) v = "NULL";
+                                       GLib.message ("Attribute: "+k+"="+v);
+                               }*/
+                               assert ((node as DomElement).get_attribute ("xmlns:magic") == 
"http://hogwarts.co.uk/magic";);
+                               assert ((node as DomElement).get_attribute_ns 
("http://www.w3.org/2000/xmlns/";, "magic") == "http://hogwarts.co.uk/magic";);
+                               assert ((node as DomElement).get_attribute ("xmlns:products") == 
"http://diagonalley.co.uk/products";);
+                               assert ((node as DomElement).get_attribute_ns 
("http://www.w3.org/2000/xmlns/","products";) == "http://diagonalley.co.uk/products";);
+                               assert (node.lookup_prefix ("http://diagonalley.co.uk/products";) == 
"products");
+                               assert (node.lookup_namespace_uri ("products") == 
"http://diagonalley.co.uk/products";);
+                       } catch (GLib.Error e) {
+                               GLib.message (e.message);
+                               assert_not_reached ();
+                       }
+               });
                Test.add_func ("/gxml/gom-element/namespace_uri", () => {
                        try {
                                GomDocument doc = new GomDocument.from_string ("<Potions><magic:Potion 
xmlns:magic=\"http://hogwarts.co.uk/magic\"; 
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]