Wai Yan
Wai Yan

Reputation: 582

OneDrive OData 4 Filtering search results using UTF8 characters

I am trying to filter the search contents from OneDrive Search API. This is the request without the filter where the original query keyword is 中英字典 whose UTF-8 encoded value is %25E4%25B8%25AD%25E8%258B%25B1%25E5%25AD%2597%25E5%2585%25B8

The request without the filter is like this.

https://api.onedrive.com/v1.0/drive/root:%2F:/view.search?q=%25E4%25B8%25AD%25E8%258B%25B1%25E5%25AD%2597%25E5%2585%25B8&access_token=$access_token

The use case is to find the matching keyword in the name so I need add a filter like filter=contains(name,'$keyword').

The corresponding request with the filter is

https://api.onedrive.com/v1.0/drive/root:%2F:/view.search?q=%25E4%25B8%25AD%25E8%258B%25B1%25E5%25AD%2597%25E5%2585%25B8&filter=contains%28name%2C%27%255Cu4E2D%255Cu82F1%255Cu5B57%255Cu5178%27%29&access_token=$access_token

The first request will give me the correct results for both ascii and non-ascii characters, but the second one gives me the correct results only for ascii characters and does not work for url-encoded UTF-8 characters (only returns empty results).

I have tried encodings from this post as well but they also do not work.

Is this a bug from OneDrive or am I using a wrong type of encoding for $filter?

Upvotes: 0

Views: 356

Answers (1)

Mostafa Khodakarami
Mostafa Khodakarami

Reputation: 830

Use it:

urlFilter += ` and indexof(Name,'` + encodeURIComponent(this.Name) + `') gt -1`;

this.Name comes from my input.

Copied from my working project.

Upvotes: 1

Related Questions