Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an invisible character that is not regarded as whitespace?

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.

like image 905
CodeBlue Avatar asked Nov 12 '13 17:11

CodeBlue


People also ask

Is there an invisible character other than space?

Unicode characters you can not see In Unicode there are a lot of invisible characters: regular white-space characters (e.g. U+0020 SPACE), language specific fillers (e.g. U+3164 HANGUL FILLER of the Korean Hangual alphabet), or special characters (e.g. U+2800 BRAILLE PATTERN BLANK).

What is a non whitespace character?

In word processing and digital typesetting, a non-breaking space, , also called NBSP, required space, hard space, or fixed space (though it is not of fixed width), is a space character that prevents an automatic line break at its position.

Is there an invisible ascii character?

There is actually a truly invisible character: U+FEFF . This character is called the Byte Order Mark and is related to the Unicode 8 system. It is a really confusing concept that can be explained HERE The Byte Order Mark or BOM for short is an invisible character that doesn't take up any space.


1 Answers

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;   } 
like image 65
Michael Konietzka Avatar answered Sep 20 '22 17:09

Michael Konietzka