Fix for getElementsByTagName("*")
David Faure
faure at kde.org
Wed Jun 25 02:20:30 CEST 2003
In the 3.1 branch, TagNodeListImpl was using m_id==0 to mean "no match".
However there was no way to get getElementsByTagName("*") to work.
Like in HEAD, I changed it so that m_id==0 means "all tags",
so I had to use another value to mean "no match at all", e.g. when specifying
a tag name that isn't in the tagId() maps yet. I used -1 (eek).
This fixes getElementsByTagName("*") and getElementsByTagNameTS("*","*").
I checked that getElementsByTagNameTS("foo","*") returns 0 elements.
Anything else I should check?
--- dom_nodeimpl.cpp 22 Jun 2003 16:01:23 -0000 1.192.2.5
+++ dom_nodeimpl.cpp 24 Jun 2003 23:14:43 -0000
@@ -1402,8 +1402,15 @@ NodeListImpl* NodeBaseImpl::getElementsB
if (namespaceURI && namespaceURI->l && namespaceURI->s[0] == '*')
idMask &= ~NodeImpl_IdNSMask;
- return new TagNodeListImpl( this,
- getDocument()->tagId(namespaceURI, localName, true), idMask);
+ Id id = 0; // 0 means "all items"
+ if ( (idMask & NodeImpl_IdLocalMask) || namespaceURI ) // not getElementsByTagName("*")
+ {
+ id = getDocument()->tagId( namespaceURI, localName, true, 0 );
+ if ( !id ) // not found -> we want to return an empty list, not "all items"
+ id = (Id)-1; // HACK. HEAD has a cleaner implementation of TagNodeListImpl it seems.
+ }
+
+ return new TagNodeListImpl( this, id, idMask );
}
// I don't like this way of implementing the method, but I didn't find any
@@ -1723,8 +1730,8 @@ NodeImpl *TagNodeListImpl::item ( unsign
bool TagNodeListImpl::nodeMatches( NodeImpl *testNode ) const
{
- return ( testNode->isElementNode() && m_id &&
- (testNode->id() & m_idMask) == m_id);
+ return testNode->isElementNode() &&
+ ((testNode->id() & m_idMask) == m_id);
}
NameNodeListImpl::NameNodeListImpl(NodeImpl *n, const DOMString &t )
--
David FAURE, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
Qtella users - stability patches at http://blackie.dk/~dfaure/qtella.html
More information about the Khtml-devel
mailing list