Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always escape RegExp when building query in mongoose connector #10499

Merged
merged 3 commits into from
Jun 28, 2021

Conversation

vkarpov15
Copy link
Contributor

Fix #10348

What does it do?

In a couple places the mongoose connector doesn't escape regexps before passing them to MongoDB

Why is it needed?

See #10348. In short, making a request to http://localhost:1337/restaurants?name_contains=lorem\ throws an error because of the trailing backslash.

How to test it?

Follow the quickstart using MongoDB and make a request to http://localhost:1337/restaurants?name_contains=lorem\. Without this PR it will throw an error. With this PR, it will return an empty array as expected.

Related issue(s)/PR(s)

#10348

@strapi-cla
Copy link

strapi-cla commented Jun 16, 2021

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Jun 21, 2021

Codecov Report

Merging #10499 (d705b12) into master (db34e73) will not change coverage.
The diff coverage is n/a.

❗ Current head d705b12 differs from pull request most recent head 361158c. Consider uploading reports for the commit 361158c to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master   #10499   +/-   ##
=======================================
  Coverage   58.01%   58.01%           
=======================================
  Files         185      185           
  Lines        6431     6431           
  Branches     1400     1400           
=======================================
  Hits         3731     3731           
  Misses       2236     2236           
  Partials      464      464           
Flag Coverage Δ
front ∅ <ø> (∅)
unit 58.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db34e73...361158c. Read the comment docs.

@derrickmehaffy derrickmehaffy requested a review from a team June 21, 2021 18:11
@derrickmehaffy derrickmehaffy added the issue: bug Issue reporting a bug label Jun 21, 2021
@petersg83
Copy link
Contributor

Thank you, it looks good to me. Can you please add a test to cover this usecase please?
It's in the file packages/core/strapi/tests/search.test.e2e.js

@vkarpov15
Copy link
Contributor Author

@petersg83 sure, I'll take a look at that later this week.

@vkarpov15
Copy link
Contributor Author

@petersg83 added it in bea8313

@alexandrebodin alexandrebodin requested review from petersg83 and removed request for a team June 28, 2021 07:57
@petersg83 petersg83 added this to the 3.6.6 milestone Jun 28, 2021
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, works perfectly!

Side node: I first tested with mongo 3.6 and the test wasn't failing. I switched to mongo 4.4 and then it failed correctly.

@abdonrd
Copy link
Contributor

abdonrd commented Aug 6, 2021

@petersg83 @vkarpov15 After this... This query stop working on my side 😕

{
  seasons(where: { slug_contains: "fms-.*-2021-2022" }) {
    slug
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MongoDB error when requested has backslash
6 participants