Summary: | XPathEvaluator behavior does not match Firefox - substring() and empty element | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Jesse Costello-Good <jesse> | ||||
Component: | XML | Assignee: | Alexey Proskuryakov <ap> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | darin, ddkilzer | ||||
Priority: | P2 | ||||||
Version: | 420+ | ||||||
Hardware: | Mac | ||||||
OS: | OS X 10.4 | ||||||
Bug Depends on: | |||||||
Bug Blocks: | 10489 | ||||||
Attachments: |
|
Description
Jesse Costello-Good
2006-12-12 14:43:45 PST
// #1: // An empty node value causes the substring() function to return true when it should return false. var strXML = '<data><record id="-a-"></record><record id="a-a">-hi-</record></data>'; var doc = (new DOMParser()).parseFromString(strXML, "text/xml"); var xpe = new XPathEvaluator(); var objResult = xpe.evaluate("//record[substring(.,1,1)='-']", doc, null, 0, null); var itm = null; var objNodes = []; while (itm = objResult.iterateNext()) objNodes.push(itm); assertEquals(1, objNodes.length); // Safari yields 2 // #2 // function name() does not work with attribute nodes var strXML = '<data><record id="-a-" a="v">???</record><record id="a-a">{abc}</record></data>'; var doc = (new DOMParser()).parseFromString(strXML, "text/xml"); var xpe = new XPathEvaluator(); var objResult = xpe.evaluate("//@*[name()='id']", doc, null, 0, null); var itm = null; var objNodes = []; while (itm = objResult.iterateNext()) objNodes.push(itm); assertEquals(2, objNodes.length); // Safari yields 0 I split this out in to two different issues. #2 is moved to bug 12340. This appears to be a general problem in our XPath code - all C++ string literals are treated as boolean values. Easy to fix by adding another constructor to XPath::Value, but I cannot understand how this occurs; suspecting a gcc bug. Please tell me I'm wrong :-). Test case: ----------------------- #include <stdio.h> class String { public: String(const char*) {} }; class Value { public: Value(bool) { printf("bool\n"); } Value(const String&) { printf("String\n"); } }; int main() { Value val(""); } ----------------------- (In reply to comment #4) > This appears to be a general problem in our XPath code - all C++ string > literals are treated as boolean values. > > Easy to fix by adding another constructor to XPath::Value, but I cannot > understand how this occurs; suspecting a gcc bug. Please tell me I'm wrong :-). I believe this Google Groups thread answers it: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/73ab483d2ef241c/487423eb73ee10d6%23487423eb73ee10d6 The replies in this thread point out that pointers can be converted to bool - but a string literal is not a pointer, it's "const char[n]" (with a deprecated conversion allowing it to be converted to char*). OTOH, the two transformations needed to get from a string literal to a bool fall into different categories (lvalue transformation and conversion), and are thus allowed in a standard conversion sequence, see section 13.3.3.1 of the standard. Not that I can claim complete understanding now, but I'm convinced. Created attachment 12721 [details]
proposed fix
Comment on attachment 12721 [details]
proposed fix
r=me
Committed revision 19225. |