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.
Created attachment 12973 [details] Small example for reproducing this bug.
(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. >
A workaround is to use full XPath syntax: "self::*[@class='test']".
Better yet, "self::node()[@class='test']"
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']".
https://bugzilla.mozilla.org/show_bug.cgi?id=369522
*** Bug 17410 has been marked as a duplicate of this bug. ***
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!