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

org.sonar.l10n.java.rules.squid.S2639.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

Regular expressions are powerful but tricky, and even those long used to using them can make mistakes.

The following should not be used as regular expressions:

  • . - matches any single character. Used in replaceAll, it matches everything
  • | - normally used as an option delimiter. Used stand-alone, it matches the space between characters
  • File.separator - matches the platform-specific file path delimiter. On Windows, this will be taken as an escape character

Noncompliant Code Example

String str = "/File|Name.txt";

String clean = str.replaceAll(".",""); // Noncompliant; probably meant to remove only dot chars, but returns an empty string
String clean2 = str.replaceAll("|","_"); // Noncompliant; yields _/_F_i_l_e_|_N_a_m_e_._t_x_t_
String clean3 = str.replaceAll(File.separator,""); // Noncompliant; exception on Windows




© 2015 - 2025 Weber Informatics LLC | Privacy Policy