Bug 17725 - XPath should be case insensitive for HTML
Summary: XPath should be case insensitive for HTML
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: XML (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.4
: P4 Minor
Assignee: Alexey Proskuryakov
URL: http://chivil.com/demos/safari+xpath/
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-08 09:57 PST by Romuald Brunet
Modified: 2009-05-27 10:22 PDT (History)
1 user (show)

See Also:


Attachments
proposed fix (6.61 KB, patch)
2009-05-27 03:34 PDT, Alexey Proskuryakov
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Romuald Brunet 2008-03-08 09:57:26 PST
It is not necessarily a bug (since XML is case sensitive), but I've found that XPath implementation in Safari differs from some other browsers (Firefox and Opera).

For exemple, in a xhtml 1.0 document, retrieving .//IMG won't return anything (either if the tags are uppercase, which is invalid xhtml, or if they are not).
You can check the url for a practical example

Found this bug because I'm used to use uppercase for tags in CSS selectors.

Since this behavior applies in Firefox and Opera, you may choose to change Safari's implementation.
Comment 1 Alexey Proskuryakov 2009-05-27 02:59:54 PDT
I don't see any reason to remain incompatible with other engines in this respect, patch forthcoming.
Comment 2 Alexey Proskuryakov 2009-05-27 03:34:16 PDT
Created attachment 30701 [details]
proposed fix
Comment 3 Darin Adler 2009-05-27 09:29:35 PDT
Comment on attachment 30701 [details]
proposed fix

> +            if (node->nodeType() != Node::ELEMENT_NODE)
> +                return false;

How about isElementNode() instead?

> +            if (node->isHTMLElement() && node->document()->isHTMLDocument()) {
> +                // Paths without namespaces should match HTML elements in HTML documents despite those having an XHTML namespace. Names are compared case-insensitively.
> +                return equalIgnoringCase(static_cast<Element*>(node)->localName(), name) && (namespaceURI.isNull() || namespaceURI == node->namespaceURI());
> +            } else
> +                return static_cast<Element*>(node)->hasLocalName(name) && namespaceURI == node->namespaceURI();

We normally don't do else after return.

r=me
Comment 4 Alexey Proskuryakov 2009-05-27 10:22:27 PDT
Committed <http://trac.webkit.org/changeset/44190>.

(In reply to comment #3)
> How about isElementNode() instead?

Node::ELEMENT_NODE is used elsewhere in this file, it seemed good for consistency.

> We normally don't do else after return.

Fixed.