A micro-library that removes Unicode control characters from a string and replaces them with the equivalent Control Picture. The primary use case is envisaged to be preventing log injection attacks (in combination with other techniques). By default control codes associated with formatting (tab, new line and carriage return) are not converted. Only C0 unicode control codes are covered,
Requires Java 8 or above.
If using Maven, the following dependency can be added to your pom.xml:
<dependency>
<groupId>com.ncredinburgh</groupId>
<artifactId>in-control</artifactId>
<version>1.1</version>
</dependency>
The controlCharactersToPictures
method can then be imported statically thus:
import static com.ncredinburgh.incontrol.InControl.controlCharactersToPictures;
class SomeClass {
public String someMethod(final String someInput) {
return controlCharactersToPictures(someInput);
}
}
The full API can be found in the Javadoc.
For a given string that contains control codes, return a new string containing pictures in their place. Excludes formatting codes (tab, new line, carriage return)
For a given string that contains control codes, return a new string containing pictures in their place. When second parameter is false, exclude formatting codes (tab, new line, carriage return) from replacement, when true, include them.