Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
johan_wigert
Active Participant

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...

1 Comment