...
In order to correctly use escape sequences pertaining to String
literals, an understanding of how they are interpreted is essential. For example, SQL
statements written in Java, sometimes require certain special escape characters or sequences (for instance, sequences containing \t
, \n
, \r
). In SQL
queries, all escape sequences must be preceded by an extra backslash for correct interpretation.
As yet another example, consider the {{ Wiki Markup Pattern
}} class that finds extensive use in performing regular expression related tasks. In Java, a given {{String
}} literal used for pattern matching is compiled into an instance of the {{Pattern
}} type. If the pattern to be matched contains an undesired escape sequence such as a '\n', to avoid it being interpreted by the Java bytecode compiler as an escape sequence, the {{Pattern
}} class requires the literal to be preceded by a backslash ('\[]{}\n', which now correctly denotes back references instead of a new line). unmigrated-wiki-markup
In general, for a particular escape character of the form '\X', the equivalent Java representation is "{}\[]\X". As an aside, this particular condition gains remarkable importance in automatic exploit signature detection systems and filters that rely on patter matching.
Noncompliant Code Example
...