dotnet / dotnet/roslynator

RCS1155: use StringComparison false positive

Open
#641 1 comment 0 reactions 0 assignees View on GitHub
Area-Analyzers Bug
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

**Product and Version Used**:
Roslynator 2.3.0
Visual Studio 16.4.4

**Steps to Reproduce**:

Consider this Linq code running against a SQL database with a case sensitive collation.

This is attempting to do a case insensitive search

`KitJournals.Where (k => k.UserId.ToUpper() == "osullirx".ToUpper()).Dump();
`

and results in this SQL

```
SELECT
...
FROM [dbo].[KitJournal] AS [Extent1]
WHERE ((UPPER([Extent1].[UserId])) = (UPPER(N'osullirx')))
OR ((UPPER([Extent1].[UserId]) IS NULL) AND (UPPER(N'osullirx') IS NULL))
```

Accepting RCS1155 suggestion changes the code to:

`KitJournals.Where (k => k.UserId.Equals("osullirx", StringComparison.OrdinalIgnoreCase)).Dump();
`

which results in this SQL which does a case sensitive search, the opposite of what was expected

```
SELECT
...
FROM [dbo].[KitJournal] AS [Extent1]
WHERE N'osullirx' = [Extent1].[UserId]

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the LINQ examples from the issue against a SQL database with a case-sensitive collation, then compare the generated SQL before and after accepting RCS1155. Done means the analyzer no longer produces a misleading suggestion for this query pattern, with the SQL behavior matching the intended case-insensitive search.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.