When developing an OData service for searching for contact persons by name, I came across a scenario where the name contains the special character ' (single quote character). As an example, the user would like to search for contact persons with the last name O'Reilly.
The URL encoding of the single quote character is %27
. First I just tried the following: https://servername/sap/opu/odata/SAP/Z_CONTACT_PERSON_SRV/ContactSet?$format=json&$filter=substringo...
This lead to an error with HTTP status code 400 and the message "Invalid token detected at position &" with exception /IWCOR/CX_DS_EXPR_SYNTAX_ERROR.
As you might already have guessed, the issue is that %27
is used to enclose the search string. When adding a single %27
within the search string, the parser of the $filter
expression gets confused.
The solution is to escape the single quote by adding a single quote before it: https://servername/sap/opu/odata/SAP/Z_CONTACT_PERSON_SRV/ContactSet?$format=json&$filter=substringo...
This blog post first appeared on the Developer Voyage blog at https://www.developervoyage.com/2019/09/03/odata-url-encoding-of-single-quote-in-a-search-string.htm...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |