rspec/rules/S1127/rule.adoc
jtingsanchali 96d9ddb930
RULEAPI-755 Update CWE URLs by removing .html suffix and update with https protocol (#926)
* Change affects only see.adoc and rule.adoc files, not comments-and-links.adoc files
2022-04-07 08:53:59 -05:00

37 lines
741 B
Plaintext

Strings, just like any other ``++Object++``, should be compared using the ``++equals()++`` method.
Using ``++==++`` or ``++!=++`` compares references rather than values, and usually does not work.
== Noncompliant Code Example
[source,text]
----
if (variable == "foo") { /* ... */ }
if (variable != "foo") { /* ... */ }
----
== Compliant Solution
[source,text]
----
if ("foo".equals(variable)) { /* ... */ }
if (!"foo".equals(variable)) { /* ... */ }
----
== See
* https://cwe.mitre.org/data/definitions/597[MITRE, CWE-597] - Use of Wrong Operator in String Comparison
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]