Commons JXPath
  1. Commons JXPath
  2. JXPATH-154

Resetting the default namespace causes a serious endless loop when requesting .asPath() on a node.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Labels:
      None
    • Environment:

      jxpath eclipse plugin from orbit

      Description

      sample smaller case:

      <...>
       <b:foo xmlns:b="bla" xmlns="test111">    <!--  No nodes are placed in the tree within ns "test111" but the attribute is still there.-->
        <b:bar>a</b:bar>                         <!-- is in ns 'bla' -->
        <test xmlns=""></test>                   <!-- does not have a namespace -->
       </b:foo>
      </...>
      

      when requesting .asPath() on the 'test' node, it loops in org.apache.commons.jxpath.ri.NamespaceResolver.getPrefix(NodePointer, String),
      and if it didn't loop it would create a wrong xpath '//b:fo/null:test' DOMNodePointer.asPath().

      So I think that the fix should be in org.apache.commons.jxpath.ri.model.dom.DOMNodePointer.asPath()

      ....
                          String ln = DOMNodePointer.getLocalName(node);
                          String nsURI = getNamespaceURI();
                          if (nsURI == null) {
                              buffer.append(ln);
                              buffer.append('[');
                              buffer.append(getRelativePositionByName()).append(']');
                          }
                          else {
                              String prefix = getNamespaceResolver().getPrefix(nsURI);
                              if (prefix != null) {
      ...
      

      should become

      ...
                          String ln = DOMNodePointer.getLocalName(node);
                          String nsURI = getNamespaceURI();
                          if (nsURI == null || nsURI.length() == 0) { // check for empty string which means that the node doesn't have a namespace.
                              buffer.append(ln);
                              buffer.append('[');
                              buffer.append(getRelativePositionByName()).append(']');
                          }
                          else {
                              String prefix = getNamespaceResolver().getPrefix(nsURI);
                              if (prefix != null) {
      ...
      

        Activity

        Hide
        Matt Benson added a comment -

        It is a convention within JXPath code that the empty namespace be represented as a Java null. Rather than check for "" at the point you identified, I have elected to modify DOMNodePointer to translate "" to null when returning its result. In this manner JXPath's DOM handling will function in the same manner as its JDOM handling, and any other callers of the method will be fixed as well.

        Committed revision 1234036.

        Show
        Matt Benson added a comment - It is a convention within JXPath code that the empty namespace be represented as a Java null . Rather than check for "" at the point you identified, I have elected to modify DOMNodePointer to translate "" to null when returning its result. In this manner JXPath's DOM handling will function in the same manner as its JDOM handling, and any other callers of the method will be fixed as well. Committed revision 1234036.
        Hide
        Hugo de Almeida Cocharro added a comment -

        Thanks a lot, I build the current 1.4 from svn and it fixes our case.

        Show
        Hugo de Almeida Cocharro added a comment - Thanks a lot, I build the current 1.4 from svn and it fixes our case.

          People

          • Assignee:
            Unassigned
            Reporter:
            Hugo de Almeida Cocharro
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development