[ 
https://issues.apache.org/jira/browse/JXPATH-161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13744112#comment-13744112
 ] 

Michele Vivoda commented on JXPATH-161:
---------------------------------------

I think I fixed this (at least for simple paths) changing method 
doStepPredicatesStandard in SimplePathInterpreter at line 408

I changed 

 int index = indexFromPredicate(context, predicate);
 if (it.setPosition(index + 1)) {
   pointer = it.getNodePointer();
 }

To 

 int index = indexFromPredicate(context, predicate);
 if (index>=0 && it.setPosition(index + 1)) {
  pointer = it.getNodePointer();
 }


To support this check there are also the other calls to indexFromPredicate, 
some do the check that here was missing.
                
> negative index in xpath expression
> ----------------------------------
>
>                 Key: JXPATH-161
>                 URL: https://issues.apache.org/jira/browse/JXPATH-161
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4
>            Reporter: Michele Vivoda
>            Priority: Minor
>         Attachments: TestNegativeIndex.java
>
>
> JXPath seems to handle incorrectly negative indexes in XPath expressions 
> Given xml <root><a>1<a></root> and xpath "/root/a[-1]"
> Xalan and Saxon match no node
> JXPath matches <a>.
> The same happens also for expressions "/root/a[-2]" and "/root/a[0]" (in 
> XPath index starts with one)
> This problem does not affect xpath on beans, that seems to work correctly, 
> but is present when performing xpath on DOM.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to