[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenonbeta/kdom/core
From:       Nikolas Zimmermann <wildfox () kde ! org>
Date:       2005-08-28 19:47:18
Message-ID: 1125258438.189745.3554.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 454397 by wildfox:

Fix lookupNamespaceURI & lookupNamespacePrefix -> fixing two XPath crashes


 M  +31 -18    NodeImpl.cpp  


--- trunk/kdenonbeta/kdom/core/NodeImpl.cpp #454396:454397
@@ -945,13 +945,17 @@
     if(!_prefix || _prefix->isEmpty())
         return 0;
 
+	QString _prefixString = (_prefix ? _prefix->string() : QString::null);
+
     switch(nodeType())
     {
         case ELEMENT_NODE:
         {
             // Note: prefix could be "null" in this case we are looking for default \
namespace  DOMStringImpl *ns = namespaceURI();
-            if((ns && !ns->isEmpty()) && DOMString(prefix()) == DOMString(_prefix))
+			QString prefixString = (prefix() ? prefix()->string() : QString::null);
+
+            if((ns && !ns->isEmpty()) && prefixString == _prefixString)
                 return ns;
 
             if(hasAttributes())
@@ -962,18 +966,21 @@
                     NodeImpl *node = attributes()->item(i);
                     AttrImpl *attr = static_cast<AttrImpl *>(node);
 
-                    if(DOMString(attr->prefix()) == DOMString("xmlns") &&
-                       DOMString(attr->localName()) == DOMString(_prefix))
-                    { // non default namespace
+					QString attrPrefix = (attr->prefix() ? attr->prefix()->string() : \
QString::null); +					QString attrLocalName = (attr->localName() ? \
attr->localName()->string() : QString::null); +
+                    if(attrPrefix == QString::fromLatin1("xmlns") && attrLocalName \
== _prefixString) +                    {
+						// non default namespace
                         DOMStringImpl *value = attr->value();
                         if(value && !value->isEmpty())
                             return value;
 
                         return 0;
                     }
-                    else if(DOMString(attr->localName()) == DOMString("xmlns") &&
-                            (!_prefix || _prefix->isEmpty()))
-                    { // default namespace
+                    else if(attrLocalName == QString::fromLatin1("xmlns") && \
(!_prefix || _prefix->isEmpty())) +                    {
+						// default namespace
                         DOMStringImpl *value = attr->value();
                         if(value && !value->isEmpty())
                             return value;
@@ -1018,13 +1025,15 @@
 
 DOMStringImpl *NodeImpl::lookupNamespacePrefix(DOMStringImpl *_namespaceURI, const \
ElementImpl *originalElement) const  { 
-    DOMString ns(_namespaceURI);
+	QString namespaceURIString = (namespaceURI() ? namespaceURI()->string() : \
QString::null); +	QString _namespaceURIString = (_namespaceURI ? \
_namespaceURI->string() : QString::null);  
-    if(!ns.isEmpty() && DOMString(namespaceURI()) == ns && (prefix() && \
                !prefix()->isEmpty()) &&
-       DOMString(originalElement->lookupNamespaceURI(prefix())) == ns)
-    {
+	DOMStringImpl *lookedUp = (originalElement->lookupNamespaceURI(prefix()));
+	QString lookedUpString = (lookedUp ? lookedUp->string() : QString::null);
+
+	if(!_namespaceURIString.isEmpty() && namespaceURIString == _namespaceURIString &&
+	   (prefix() && !prefix()->isEmpty()) && lookedUpString == _namespaceURIString)
         return prefix();
-    }
 
     if(hasAttributes())
     {
@@ -1034,12 +1043,16 @@
             NodeImpl *node = attributes()->item(i);
             AttrImpl *attr = static_cast<AttrImpl *>(node);
 
-            DOMStringImpl *local = attr->localName();
-            if(DOMString(attr->prefix()) == DOMString("xmlns") && \
                DOMString(attr->value()) == ns &&
-               DOMString(originalElement->lookupNamespaceURI(local)) == ns)
-            {
-                return local;
-            }
+			QString attrValue = (attr->value() ? attr->value()->string() : QString::null);
+			QString attrPrefix = (attr->prefix() ? attr->prefix()->string() : QString::null);
+			QString attrLocalName = (attr->localName() ? attr->localName()->string() : \
QString::null); +
+			DOMStringImpl *lookedUp = \
(originalElement->lookupNamespaceURI(attr->localName())); +			QString lookedUpString \
= (lookedUp ? lookedUp->string() : QString::null); +
+			if(attrPrefix == QString::fromLatin1("xmlns") && attrValue == _namespaceURIString \
&& +			   lookedUpString == _namespaceURIString)
+				return attr->localName();
         }
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic