All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S2479.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

Non-encoded control characters and whitespace characters are often injected in the source code because of a bad manipulation. They are either invisible or difficult to recognize, which can result in bugs when the string is not what the developer expects. If you actually need to use a control character use their encoded version:

  • ASCII, for example \n and \t
  • Unicode, for example U+000D and U+0009

This rule raises an issue when the following characters are seen in a string literal:

Exceptions

How to fix it

Code examples

Noncompliant code example

string tabInside = "A	B";                 // Noncompliant: contains a tabulation
string zeroWidthSpaceInside = "foo​bar";     // Noncompliant: contains a U+200B character inside
Console.WriteLine(zeroWidthSpaceInside);    // Prints "foo?bar"

Compliant solution

string tabInside = "A\tB";                      // Compliant: escaped value
string zeroWidthSpaceInside = "foo\u200Bbar";   // Compliant: escaped value
Console.WriteLine(zeroWidthSpaceInside);        // Prints "foo?bar"

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy