Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...