Search code examples
javascriptescapingodataquote

how to escape single quote in odata filter uri?


I tried to escape the single quote when preparing the query in JS this way:

_value.replace(/'/g,'%27')

and this way:

_value.replace(/\'/g,'\\\'');

both doesn't seem to work

You can see an example here: http://services.odata.org/V3/Northwind/Northwind.svc/Orders?$select=Freight,CustomerID&$filter=ShipName+eq+'B's%20Beverages'&$format=json

Does anyone know how to escape the single quote?

Thanks


Solution

  • The single quote need to be doubled, for instance:

    ShipName+eq+'B''sBeverages'
    

    instead of

    ShipName+eq+'B'sBeverages'