CA1308: Normalize strings to uppercase
Property | Value |
---|---|
Rule ID | CA1308 |
Title | Normalize strings to uppercase |
Category | Globalization |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 8 | No |
Cause
An operation normalizes a string to lowercase.
Rule description
Strings should be normalized to uppercase. A small group of characters, when they are converted to lowercase, cannot make a round trip. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters.
How to fix violations
Change operations that convert strings to lowercase so that the strings are converted to uppercase instead. For example, change String.ToLower(CultureInfo.InvariantCulture)
to String.ToUpper(CultureInfo.InvariantCulture)
.
When to suppress warnings
It's safe to suppress a warning when you're not making security decisions based on the result of the normalization (for example, when you're displaying the result in the UI).
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA1308
// The code that's violating the rule is on this line.
#pragma warning restore CA1308
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA1308.severity = none
For more information, see How to suppress code analysis warnings.