rspec/rules/S2479/java/rule.adoc

49 lines
1.7 KiB
Plaintext
Raw Normal View History

== 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 (ex: ASCII ``++\n,\t,++``... or Unicode ``++U+000D, U+0009,++``...).
This rule raises an issue when the following characters are seen in a literal string:
* https://en.wikipedia.org/wiki/ASCII#Control_characters[ASCII control character]. (character index < 32 or ++=++ 127)
* Unicode https://en.wikipedia.org/wiki/Unicode_character_property#Whitespace[whitespace characters].
* Unicode https://en.wikipedia.org/wiki/C0_and_C1_control_codes[C0 control characters]
* Unicode characters ``++U+200B, U+200C, U+200D, U+2060, U+FEFF, U+2028, U+2029++``
No issue will be raised on the simple space character. Unicode ``++U+0020++``, ASCII 32.
2020-06-30 12:48:07 +02:00
=== Noncompliant code example
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 12:48:07 +02:00
----
String tabInside = "A B"; // Noncompliant, contains a tabulation
String zeroWidthSpaceInside = "foobar"; // Noncompliant, it contains a U+200B character inside
char tab = ' ';
----
=== Compliant solution
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 12:48:07 +02:00
----
String tabInside = "A\tB"; // Compliant, uses escaped value
String zeroWidthSpaceInside = "foo\u200Bbar"; // Compliant, uses escaped value
char tab = '\t';
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]