最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to escape single quote in odata filter uri? - Stack Overflow

programmeradmin0浏览0评论

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: .svc/Orders?$select=Freight,CustomerID&$filter=ShipName+eq+'B's%20Beverages'&$format=json

Does anyone know how to escape the single quote?

Thanks

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

Share Improve this question asked Oct 11, 2013 at 13:17 Mohamed Ali JAMAOUIMohamed Ali JAMAOUI 14.7k14 gold badges78 silver badges123 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 15

The single quote need to be doubled, for instance:

ShipName+eq+'B''sBeverages'

instead of

ShipName+eq+'B'sBeverages'

Used this code to replace single quote... Its working..

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

as per example 3 of http://docs.oasis-open.org/odata/odata/v4.01/cs01/part2-url-conventions/odata-v4.01-cs01-part2-url-conventions.html#sec_URLComponents

you need escape a quote with a quote (also, don't forget to handle & : encode to %26 )

so "bit's & bobs" becomes "bit''s %26 bobs"

发布评论

评论列表(0)

  1. 暂无评论