It is safe to suppress a warning from this rule when the library or application is intended for a limited local audience and will therefore not be localized.
This is actually incorrect. If making security decisions based on the result or doing path comparisons, you should explicitly specify a string comparison, passing one of StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase.
The following example shows a method that incorrectly compares the start of an URL:
[C#]
using System;
using System.Globalization;
using System.Threading;
namespace Samples
{
class Program
{
static void Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
string url = "file:///C|/MyFile.txt";
if (string.Compare(url, 0, "FILE:", 0, 5, true) == 0)
{
Console.WriteLine("File path");
}
else
{
Console.WriteLine("Something else");
}
}
}
}
The above outputs the following:
Something else
To fix the above violation specify StringComparison.OrdinalIgnoreCase.
The following example shows this.
[C#]
using System;
using System.Globalization;
using System.Threading;
namespace Samples
{
class Program
{
static void Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
string url = "file:///C|/MyFile.txt";
if (string.Compare(url, 0, "FILE:", 0, 5, StringComparison.OrdinalIgnoreCase) == 0)
{
Console.WriteLine("File path");
}
else
{
Console.WriteLine("Something else");
}
}
}
}
The above outputs the following:
File path