Contains Query by default allow Regex, how I can disable that , as when I make request with title_contains = "(" return error

System Information
  • **Strapi Version3.2.4:
  • **Operating SystemUbntu serve:
  • **Databasemongodb:
  • **Node Version13.7:
  • NPM Version:
  • Yarn Version:

Let us say we have Articles collection type that have title field as string

When I make a get request /articles?title_contains=(
I will get this error : error MongoError: Regular expression is invalid: missing )
And I found out that it is because contains parameter support Regex
So the Question is how I can disable it, or make a work around
As I want to be able to search for titles with special characters

Can you please provide content to your issue and not just a title. Thank you.

I did, thanks for the hint

Oh this is an interesting one I haven’t seen. I’ll do some testing and get back to you.

1 Like

I found the solution, I just created a escape function for Regex characters :
function escapeRegex(string) {
return string.replace(/[-/\^$*+?.()|[]{}]/g, ‘\$&’);

and applied it on the string that comes after contains=
so all Regex characters will be escaped so it will be treated like normal string

1 Like