Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive Query issue with single quote and back slash

We have implemented several applications which are interacting with google drive through Google Drive SDK v2.

We are facing a problem with "single quote" and "back slash"

The problem is in Google Drive you are able to create files and folders containing special characters, but if you are going to pass the same file or folder name using API it is giving error, invalid query.

We know usually for this kind of scenarios it is recommended to use escape characters or encoding to pass the value but the problem is , Google will not understand it is a escape character or the encoding as it expects a string as Query.

Example: title = 'hello dev's 1\2\3' for back slash I already found the answer which is adding a \ before single quote, but I am still figuring out for .

I was wondering if anyone knows how to resolve this, or if it is a known behavior.

Thanks,

like image 456
Milad Rezazadeh Avatar asked Aug 25 '15 06:08

Milad Rezazadeh


1 Answers

I have found the answer for this, it was pretty much simple, but somehow there was not enough documentation about it, when using google drive API, in order to pass special characters to google, it is required to use "back-slash" before your special character.

so for example you are going to set your search query like this,

'title = martin's paper\article' \\ result : invalid_query error 

it should be like this

'title = martin\'s paper\\article' \\ google will accept it [ok]

I hope it helps you guys out there,

Thanks,

like image 110
Milad Rezazadeh Avatar answered Oct 15 '22 14:10

Milad Rezazadeh