RESOLVED INVALID 12632
XPath: Cannot apply predicate to context node.
https://bugs.webkit.org/show_bug.cgi?id=12632
Summary XPath: Cannot apply predicate to context node.
L. Daniel Burr
Reported 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.
Attachments
Small example for reproducing this bug. (902 bytes, text/html)
2007-02-06 09:41 PST, L. Daniel Burr
no flags
L. Daniel Burr
Comment 1 2007-02-06 09:41:02 PST
Created attachment 12973 [details] Small example for reproducing this bug.
L. Daniel Burr
Comment 2 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. >
Alexey Proskuryakov
Comment 3 2007-02-06 10:19:04 PST
A workaround is to use full XPath syntax: "self::*[@class='test']".
Alexey Proskuryakov
Comment 4 2007-02-06 10:33:53 PST
Better yet, "self::node()[@class='test']"
Alexey Proskuryakov
Comment 5 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']".
Alexey Proskuryakov
Comment 6 2007-02-06 11:17:42 PST
Alexey Proskuryakov
Comment 7 2008-02-18 02:56:39 PST
*** Bug 17410 has been marked as a duplicate of this bug. ***
Ahmad Saleem
Comment 8 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!
Note You need to log in before you can comment on or make changes to this bug.