Files - NKS0022
Use Parsing.GetInvalidPathChars()
This analyzer provides the following strings:
Context | String |
---|---|
Error List | Caller uses |
Suggestion Box | Use |
Description |
|
Extended Description
This code analyzer detects the usage of GetInvalidPathChars
from the standard Path
class found in the System.IO
namespace.
Using Path.GetInvalidPathChars()
, a weirdness has been discovered on Windows systems running .NET 6.0 or later, because that function doesn't consider the three characters: "
, <
, and >
illegal. Therefore, operations can be made to the files or folders on Windows systems with the three characters on them, causing undefined behavior.
A solution to this problem was made with GetInvalidPathChars()
from Parsing, because it takes care of this pitfall on Windows systems by placing the three characters above to the blacklist.
Analysis Comparison
To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:
Before the fix
After the fix
Suppression
You can suppress this suggestion by including it in the appropriate place, whichever is convenient.
For more information about how to suppress any warning issued by the Nitrocid analyzer, visit the below page:
Recommendation
We recommend that every caller which use this function use the recommended abovementioned method.