I am working with an existing framework where I have to set a certain attribute to blank if some conditions are satisfied. Unfortunately, the framework doesn't allow setting only whitespace to the attribute value. Specifically, it does a
!(org.apache.commons.lang.StringUtils.isBlank(value))
check on the value
Is it possible to somehow bypass this and set a value that looks blank/invisible to the eye but is not regarded as whitespace?
I am using a dash "-" right now, but I think it would be interesting to know if it's possible.
Try Unicode Character 'ZERO WIDTH SPACE' (U+200B). It is not a Whitespace according to WP: Whitespace#Unicode
The code of StringUtils.isBlank
will not bother it:
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(str.charAt(i)) == false)) {
return false;
}
}
return true;
}