Skip to content

InIgnoreCase queries match on substrings #4404

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

Closed
zlaval opened this issue Jun 8, 2023 · 1 comment
Closed

InIgnoreCase queries match on substrings #4404

zlaval opened this issue Jun 8, 2023 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@zlaval
Copy link

zlaval commented Jun 8, 2023

The generated query is not ok in case of using in expression with IgnoreCase.

Example:

@Document(collection = "mydata")
data class MyData(
   @Id
    val id: String,
    val name: String,
)

I have a list of names and I would like to query for documents which name is in the list case insensitively.

Using fun findAllByNameInIgnoreCase(names: List<String>) creates the following mongo query:

"name" : { "$in" : [{ "$regularExpression" : { "pattern" : "\\QTest One\\E", "options" : "i"}}, { "$regularExpression" : { "pattern" : "\\QTest Two\\E", "options" : "i"}}]}

The problem it will also match to Test Two Something.

This works just fine in case of fun findByNameIgnoreCase(names: String), which generates this query:

"name" : { "$regularExpression" : { "pattern" : "^Test One$", "options" : "i"}}

So i think this would be consistent if the generated query was:

"name" : { $in : [{ "$regularExpression" : { "pattern" : "^\\QTest One\\E$", "options" : "i"}}, { "$regularExpression" : { "pattern" : "^\\QTest Two\\E$", "options" : "i"}}]}

This would results in the expected result, as the query method does not contains Regex expression even if mongo solves case insensivity with regex.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 8, 2023
@christophstrobl
Copy link
Member

Thanks @zlaval for raising the issue.

@christophstrobl christophstrobl self-assigned this Jun 13, 2023
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2023
@mp911de mp911de changed the title Interface method generates wrong query - findAllByXXXInIgnoreCase InIgnoreCase queries match on substrings Jun 14, 2023
@mp911de mp911de added this to the 3.4.13 (2021.2.13) milestone Jun 14, 2023
mp911de pushed a commit that referenced this issue Jun 14, 2023
Mark method potentially returning null as such and remove unused imports.

See #4404
Original pull request: #4412
mp911de added a commit that referenced this issue Jun 14, 2023
Use extended switch syntax.

See #4404
Original pull request: #4412
mp911de pushed a commit that referenced this issue Jun 14, 2023
Prior to this change the generated pattern would have matched more entries than it should have. The behavior is now aligned to its counterpart not using the IgnoreCase flag.

Closes #4404
Original pull request: #4412
mp911de pushed a commit that referenced this issue Jun 14, 2023
Mark method potentially returning null as such and remove unused imports.

See #4404
Original pull request: #4412
mp911de added a commit that referenced this issue Jun 14, 2023
Use extended switch syntax.

See #4404
Original pull request: #4412
mp911de pushed a commit that referenced this issue Jun 14, 2023
Prior to this change the generated pattern would have matched more entries than it should have. The behavior is now aligned to its counterpart not using the IgnoreCase flag.

Closes #4404
Original pull request: #4412
mp911de pushed a commit that referenced this issue Jun 14, 2023
Mark method potentially returning null as such and remove unused imports.

See #4404
Original pull request: #4412
mp911de added a commit that referenced this issue Jun 14, 2023
Use extended switch syntax.

See #4404
Original pull request: #4412
mp911de pushed a commit that referenced this issue Jun 14, 2023
Prior to this change the generated pattern would have matched more entries than it should have. The behavior is now aligned to its counterpart not using the IgnoreCase flag.

Closes #4404
Original pull request: #4412
mp911de pushed a commit that referenced this issue Jun 14, 2023
Mark method potentially returning null as such and remove unused imports.

See #4404
Original pull request: #4412
mp911de added a commit that referenced this issue Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants