Daniel Li created OLINGO-940:
--------------------------------

             Summary: Doesn't support query by special characters like "&" in 
$filter expression
                 Key: OLINGO-940
                 URL: https://issues.apache.org/jira/browse/OLINGO-940
             Project: Olingo
          Issue Type: Bug
          Components: odata2-core
    Affects Versions: V2 2.0.6, V2 2.0.5, V2 2.0.4, V2 2.0.3, V2 2.0.2, V2 2.0.1
            Reporter: Daniel Li
            Priority: Critical
             Fix For: V2 2.0.7


When doing the filter "$filter=substringof('AT & T',tolower(AccountName))", the 
system will throw "Invalid filter expression: '((substringof('at '." error.

After looking at the implementation, we found there is bug when parsing query 
string in 
org.apache.olingo.odata2.core.servlet.RestUtil.extractAllQueryParameters(String)
 and 
org.apache.olingo.odata2.core.servlet.RestUtil.extractQueryParameters(String). 

For V2 2.0.1 and V2 2.0.2, it only split the query string by "&", when the 
filter value contains "&", the error is occurred. 
List<String> queryParameters 
=Arrays.asList(Decoder.decode(queryString).split("\\&")); 

>From V2 2.0.3, it still split the query string by "&", 
List<String> queryParameters = Arrays.asList(queryString.split("\\&")); 

To fix this issue, below is my suggestion(based on V2 2.0.1 & V2 2.0.2), add 
special handling after decode the query string: 
List<String> queryParameters = 
Arrays.asList(handleSpecialCharacter(Decoder.decode(queryString)).split("\\&"));
 and then add below method:

 /**
     * Handle special characters to encode characters such as "%" and "&" etc..
     * 
     * @param str
     *            A decoded query string
     * @return
     */
  private static String handleSpecialCharacter(String queryString) {
      Pattern pattern = Pattern.compile("\\'.+\\'");
      Matcher matcher = pattern.matcher(queryString);
      StringBuffer sb = new StringBuffer();
      while(matcher.find()) {
          String matchStr = matcher.group();
          String str1 = matcher.replaceFirst(matchStr.replaceAll("%", 
"%25").replaceAll("&", "%26"));
          sb.append(str1);
      }
      return sb.toString();
  }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to