You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by "Michael Bolz (JIRA)" <ji...@apache.org> on 2016/04/25 20:52:13 UTC

[jira] [Commented] (OLINGO-940) Doesn't support query by special characters like "&" in $filter expression

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

Michael Bolz commented on OLINGO-940:
-------------------------------------

Hi [~daniel.li],

from my understanding for such a filter parameter {{$filter=substringof('AT & T',tolower(AccountName))}} the parameter value must be percent encode: {{$filter=substringof(%27AT%20%26%20T%27,tolower(AccountName))}}.
And with "{{&}}" encoded as {{%26}} the request works.

You can check this also with the OData.org sample service:
Not correct encoded: [http://services.odata.org/V2/Northwind/Northwind.svc/Customers?$filter=substringof(%27AT%20&%20T%27,tolower(ContactName))]
Correct encoded: [http://services.odata.org/V2/Northwind/Northwind.svc/Customers?$filter=substringof(%27AT%20%26%20T%27,tolower(ContactName))]

Perhaps your client (e.g. browser) only encoded the spaces correct but not the "{{&}}".
Actual I think that we do not need a fix here.

Best Regards, Michael

> 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.1, V2 2.0.2, V2 2.0.3, V2 2.0.4, V2 2.0.5, V2 2.0.6
>            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 queryString
>      *            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)