Case sensitivity of element.<attributename>

David Faure david at mandrakesoft.com
Wed Nov 6 10:47:00 GMT 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

#47090 led me to investigate the case sensitivity of element.<attributename> and element.getAttribute() in IE.
It turns out that the former is fully case _sensitive_, while the latter is case insensitive (at least
in the default mode, != XHTML). See attached testcase. (Note: Mozilla doesn't support
element.<attributename> at all, so this is about IE only).

At the moment the code in ecma/kjs_dom.cpp for giving access to attributes, is simply
  DOM::DOMString attr = element.getAttribute( propertyName.string() )
... which leads to the "case insensitive" code.

To fix this, I would need to add a bool to DocumentImpl::attrId...
then I can duplicate the 4 lines of Element::getAttributeNS, so that should be all.

Would this be ok?
- -NodeImpl::Id DocumentImpl::attrId(DOMStringImpl* _namespaceURI, DOMStringImpl *_name, bool readonly)
+NodeImpl::Id DocumentImpl::attrId(DOMStringImpl* _namespaceURI, DOMStringImpl *_name, bool readonly, bool forceCaseSensitive)
 {
     // Each document maintains a mapping of attrname -> id for every attr name
     // encountered in the document.
@@ -1546,10 +1550,10 @@ NodeImpl::Id DocumentImpl::attrId(DOMStr
     if (!_namespaceURI || !strcasecmp(_namespaceURI, XHTML_NAMESPACE)) {
         // we're in HTML namespace if we know the tag.
         // xhtml is lower case - case sensitive, easy to implement
- -        if ( htmlMode() == XHtml && (id = khtml::getAttrID(n.string().ascii(), _name->l)) )
+        if ( (htmlMode() == XHtml || forceCaseSensitive) && (id = khtml::getAttrID(n.string().ascii(), _name->l)) )
             return id;
         // compatibility: upper case - case insensitive
- -        if ( htmlMode() != XHtml && (id = khtml::getAttrID(n.string().lower().ascii(), _name->l )) )
+        if ( (htmlMode() != XHtml && !forceCaseSensitive) && (id = khtml::getAttrID(n.string().lower().ascii(), _name->l )) )
             return id;
 
         // ok, the fast path didn't work out, we need the full check

A dirtier hack, to avoid any change in khtml itself (and to avoid the more complex logic above)
would be to set the htmlMode to XHTML before calling attrId, then resetting it back. Hmm.

- -- 
David FAURE, david at mandrakesoft.com, faure at kde.org
http://people.mandrakesoft.com/~david/
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9yPMl72KcVAmwbhARAi4cAKCiY3YilMVVG742ztRubISX1U/+JQCdEdCD
f18AGsIbNboPtWeRvKWjeNo=
=JMYM
-----END PGP SIGNATURE-----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20021106/b2d227ab/attachment.html>


More information about the kfm-devel mailing list