Last Comment Bug 388415 - document.evaluate throws error if context is an empty text node.
: document.evaluate throws error if context is an empty text node.
Status: UNCONFIRMED
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: unspecified
: All All
: -- normal with 1 vote (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
http://tests.novemberborn.net/browser...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-07-17 04:16 PDT by Mark Wubben
Modified: 2007-07-17 05:52 PDT (History)
3 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description Mark Wubben 2007-07-17 04:16:57 PDT
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.5pre) Gecko/20070711 Camino/1.6a1pre (like Firefox/2.0.0.5pre)
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.9a7pre) Gecko/2007071604 Minefield/3.0a7pre

Evaluating an XPATH expression using document.evaluate() throws an error if the contextNode is an empty text node.

Error thrown:

Error: uncaught exception: [Exception... "Operation is not supported"  code: "9" nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)"  location: "http://tests.novemberborn.net/browsers/gecko/xpath/evalutation-exception.html Line: 20"]

The line number corresponds with the result argument.

Reproducible: Always

Steps to Reproduce:
1. Open Firefox
2. Open the error console, make sure it's cleared
3. Go to the test case: http://tests.novemberborn.net/browsers/gecko/xpath/evalutation-exception.html
Actual Results:  
A NS_ERROR_DOM_NOT_SUPPORTED error is thrown.

Expected Results:  
No error is thrown. "[Object HTMLSpanElement]" is alerted.

This problem also occurs in Firefox 2.0.
Comment 1 Mark Wubben 2007-07-17 04:26:43 PDT
Firefox 2.0 gives the following exception:

Error: uncaught exception: [Exception... "Object cannot be created in this context"  code: "9" nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)"  location: "http://tests.novemberborn.net/browsers/gecko/xpath/evalutation-exception.html Line: 22"]
Comment 2 Olli Pettay [:smaug] 2007-07-17 04:40:24 PDT
This looks like intended behavior. Peter, could you explain why?
Is it because of http://www.w3.org/TR/xpath#section-Text-Nodes ?
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/content/xslt/src/xpath/nsXPathExpression.cpp&rev=1.22&mark=113-127#108
Comment 3 Sjoerd Visscher 2007-07-17 05:31:41 PDT
The xpath implementation does no text node normalization, so http://www.w3.org/TR/xpath#section-Text-Nodes is not the reason.

In Xopus I catch these errors, and work around it by making the parent element the context node, and prefixing the xpath expression with "node()[x]/" where x is the number of preceding siblings of the text node. Then everything works as expected.

So I think this test should just go, as empty text nodes as context will probably work just fine.
Comment 4 Peter Van der Beken [:peterv] - away till Aug 1st 2007-07-17 05:48:06 PDT
This is because the DOM and the XPath data model differ: XPath doesn't have empty text nodes. We don't enforce that everywhere in Transformiix, but probably should do more of these checks instead of less. We could just not throw in this case and return an empty result.
Comment 5 Peter Van der Beken [:peterv] - away till Aug 1st 2007-07-17 05:50:09 PDT
Also: http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathExpression-evaluate

"If the context node is a Text or a CDATASection, ..., unless the node is empty in which case it may not serve as the XPath context."
Comment 6 Sjoerd Visscher 2007-07-17 05:52:43 PDT
The same goes for document fragments.

http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/content/xslt/src/xpath/nsXPathExpression.cpp&rev=1.22&mark=128-135#108
This test fails for document fragments, but if I start at a child of the document fragment and add "../" to the xpath expression, everything works fine.

Note You need to log in before you can comment on or make changes to this bug.