Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Won't Fix
-
V2 2.0.1, V2 2.0.2
-
None
Description
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 queryString
- A decoded query string
- @return
*/
private static String handleSpecialCharacter(String queryString)Unknown macro: { 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(); }