private String escapeEqualsFromXpathNodeTest(String selectorExpression) {
        String nodeTestStart = "[";
        String nodeTestEnd = "]";
        
        // check presence of Xpath node test first
        if (!selectorExpression.contains(nodeTestStart) || !selectorExpression.contains(nodeTestEnd)) {
            return selectorExpression; //no Xpath node test return initial value - nothing to escape
        }
        
        StringBuilder selectorBuilder = new StringBuilder();
        int nodeTestStartIndex = selectorExpression.indexOf(nodeTestStart);
        int nodeTestEndIndex = selectorExpression.indexOf(nodeTestEnd);
        boolean escape = false;
        for (int i = 0; i < selectorExpression.length(); i++) {
            
            if (i == nodeTestStartIndex) {
                escape = true;
            }
            
            if (escape && selectorExpression.charAt(i) == '=') {
                selectorBuilder.append("@equals@");
            } else {
                selectorBuilder.append(selectorExpression.charAt(i));
            }
            
            if (i == nodeTestEndIndex) {
                nodeTestStartIndex = selectorExpression.indexOf(nodeTestStart);
                nodeTestEndIndex = selectorExpression.indexOf(nodeTestEnd);
                escape = false;
            }
        }
        
        return selectorBuilder.toString();
    }
private String escapeEqualsFromXpathNodeTest ( String selectorExpression ) { String nodeTestStart = "[" ; String nodeTestEnd = "]" ; if ( ! selectorExpression . contains ( nodeTestStart ) || ! selectorExpression . contains ( nodeTestEnd ) ) { return selectorExpression ; } StringBuilder selectorBuilder = new StringBuilder ( ) ; int nodeTestStartIndex = selectorExpression . indexOf ( nodeTestStart ) ; int nodeTestEndIndex = selectorExpression . indexOf ( nodeTestEnd ) ; boolean escape = false ; for ( int i = 0 ; i < selectorExpression . length ( ) ; i ++ ) { if ( i == nodeTestStartIndex ) { escape = true ; } if ( escape && selectorExpression . charAt ( i ) == '=' ) { selectorBuilder . append ( "@equals@" ) ; } else { selectorBuilder . append ( selectorExpression . charAt ( i ) ) ; } if ( i == nodeTestEndIndex ) { nodeTestStartIndex = selectorExpression . indexOf ( nodeTestStart ) ; nodeTestEndIndex = selectorExpression . indexOf ( nodeTestEnd ) ; escape = false ; } } return selectorBuilder . toString ( ) ; }
Xpath expression can gold equals characters in node tests. We have to escape those first before evaluating the
message selector expression, because equals characters do
@param selectorExpression
@return