Bug 12632 - XPath: Cannot apply predicate to context node.
Summary: XPath: Cannot apply predicate to context node.
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: XML (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 17410 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-02-06 09:30 PST by L. Daniel Burr
Modified: 2022-07-25 17:48 PDT (History)
5 users (show)

See Also:


Attachments
Small example for reproducing this bug. (902 bytes, text/html)
2007-02-06 09:41 PST, L. Daniel Burr
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description L. Daniel Burr 2007-02-06 09:30:15 PST
The following expression, which works correctly in Opera and Firefox, throws "INVALID_EXPRESSION_ERR: DOM XPath Exception 51":

.[@*[]

This is just a simple example, but basically any attempt to apply a predicate to the context node fails with this error.  As noted above, Firefox and Opera both return the context node if the predicate evaluates as true.
Comment 1 L. Daniel Burr 2007-02-06 09:41:02 PST
Created attachment 12973 [details]
Small example for reproducing this bug.
Comment 2 L. Daniel Burr 2007-02-06 09:45:49 PST
(In reply to comment #0)
> The following expression, which works correctly in Opera and Firefox, throws
> "INVALID_EXPRESSION_ERR: DOM XPath Exception 51":
> 
> .[@*[]
>

Argh, somehow that didn't paste correctly.  It should be ".[@name='test']".  Note that the attached sample is correct, and will reproduce the problem accurately.
 
> This is just a simple example, but basically any attempt to apply a predicate
> to the context node fails with this error.  As noted above, Firefox and Opera
> both return the context node if the predicate evaluates as true.
> 

Comment 3 Alexey Proskuryakov 2007-02-06 10:19:04 PST
A workaround is to use full XPath syntax: "self::*[@class='test']".
Comment 4 Alexey Proskuryakov 2007-02-06 10:33:53 PST
Better yet, "self::node()[@class='test']"
Comment 5 Alexey Proskuryakov 2007-02-06 10:51:53 PST
I think WebKit is correct here, this syntax is invalid in XPath 1.0. See rule 4 - an abbreviated step cannot have predicates.

[4] Step ::= AxisSpecifier NodeTest Predicate*	
             | AbbreviatedStep

Also, see rule 20 - since "." is not a PrimaryExpr, it cannot start a FilterExpr either.

[20] FilterExpr ::= PrimaryExpr
                    | FilterExpr Predicate

From rule 20 comes another workaround: "(.)[@class='test']".
Comment 6 Alexey Proskuryakov 2007-02-06 11:17:42 PST
https://bugzilla.mozilla.org/show_bug.cgi?id=369522
Comment 7 Alexey Proskuryakov 2008-02-18 02:56:39 PST
*** Bug 17410 has been marked as a duplicate of this bug. ***
Comment 8 Ahmad Saleem 2022-07-25 16:45:19 PDT
I am getting following behavior across all browsers:

*** Safari 15.6 on macOS 12.5 ***

Console errors when clicking link in attached test case - The string did not match the expected pattern.

*** Chrome Canary 106 ****

Console errors when clicking link in attached test case - The string '.[@class='test']' is not a valid XPath expression.

*** Firefox Nightly 104 ***

Nothing happens and there is no Console error.

_______

Comment 05 mentions that Webkit is right here, plus Firefox still has the bug open (Comment 06 was duplicate for https://bugzilla.mozilla.org/show_bug.cgi?id=164822). I think this can be considered as "RESOLVED INVALID" or "RESOLVED WONTFIX"? Thanks!