223

I just lost part of my weekend because of this ... joker - zero width space. I just used some snippets from google groups and didn't recognize that there are doubled characters, because Idea (11) didn't show them, which was causing problems with parsing config file of my app... I discovered it accidentally in vi.

Is there any way to display such things in IntelliJ (or some other way to examine files) without using external editors.

IntelliJ 11 / Mac OS 10.7

edit - sample

These two lines looks identical, in browser and also in Idea. You can see in page's code that in first - commented line there is hidden zero width space between mysql:// and localhost, which causes problems. Of course if you expect that 'joker', you can try to use search and replace it, however nobody expects the sign that should not be there, especially if he cannot see it in any way.

#db.default.url="jdbc:mysql://​localhost/play-fullcalendar"
 db.default.url="jdbc:mysql://localhost/play-fullcalendar"
biesior
  • 55,576
  • 10
  • 125
  • 182
  • 35
    This character should be banned by an international treaty. It's a weapon of massive distraction. I lost a whole day trying to find out what's the cause of a mysterious error showing up in my js console. Seriously, a zero-width character? That's a perfect recipe for trouble. What was the UTF standards committee thinking? – Nick Aug 13 '15 at 23:54
  • 6
    @Nick your comment inspired me to find why UTF included this joker thing. Check this out for the beauty of ZeroWidthCharacter: https://www.ptiglobal.com/2018/04/26/the-beauty-of-unicode-zero-width-characters/ – Deepam Gupta May 19 '21 at 07:12
  • 1
    A zero width space is also very useful on e.g. Twitter with their hashtags and all that. If you want to write "#FlatEarther", but want the hashtag to end at the "h", put a zero width space there. "er" will be normal text. – Dreamspace President Apr 02 '22 at 10:54

2 Answers2

405

Not sure what you meant, but you can permanently turn showing whitespaces on and off in Settings -> Editor -> General -> Appearance -> Show whitespaces.

Also, you can set it for a current file only in View -> Active Editor -> Show WhiteSpaces.

Edit:

Had some free time since it looks like a popular issue, I had written a plugin to inspect the code for such abnormalities. It is called Zero Width Characters locator and you're welcome to give it a try.

Community
  • 1
  • 1
Vic
  • 21,473
  • 11
  • 76
  • 97
  • 5
    ellou' Vic, thanks for reply. Unfortunately this option doesn't show 'zero width space' mentioned in subject. I'm sure that the character exists, because can display it with ie. Vi, but can't see it in Idea :/ – biesior Mar 26 '12 at 15:40
  • 2
    I see.. I guess we'll have to wait for CrazyCoder to say that it's not supported or something like this :) – Vic Mar 26 '12 at 17:47
  • Hey, I have installed the plugin.. but it doesn't really work for the zero length character that I am having a problem with.. – Thomas Beauvais Jun 03 '14 at 11:03
  • 1
    Is there a way to change the colour/style of the whitespace characters? – Will Sewell Feb 03 '15 at 09:56
  • 5
    Begining with IntelliJ-14.1 it's hidden in `Settings -> Editor -> General -> Appearance -> Show whitespaces -> Leading | Inner | Trailing` – Robert Heine Apr 08 '15 at 08:44
  • 4
    Is it possible to make the dots at white spaces bidder? like in Sublime – OlehZiniak Jun 11 '16 at 10:51
  • 1
    @vic Zero Width Characters location is fantastic! Had I installed this earlier I would have saved many hours of frustration. – Ben Clayton Mar 09 '17 at 13:10
  • 3
    @WillSewell, you may affect the color by selecting `Settings -> Editor -> Color Scheme -> General`, then within that category, go to `Text -> Whitespaces`. I changed mine from the default Foreground #505050 to #404040 , and find them visible but not distracting – chaserb May 25 '18 at 19:34
  • Thanks, but the plugin misses the \0 (binary zero) character, unfortunately. – Grigori Kochanov Mar 16 '19 at 15:39
  • @Vic How do you use this plugin? – Lloyd Banks Jul 27 '21 at 23:52
  • https://plugins.jetbrains.com/plugin/7448-zero-width-characters-locator just to find your plugin you're looking for. – Ruwen Gastrock Jul 18 '23 at 13:26
91

A very simple solution is to search your file(s) for non-ascii characters using a regular expression. This will nicely highlight all the spots where they are found with a border.

Search for [^\x00-\x7F] and check the box for Regex.

The result will look like this (in dark mode):

zero width space made visible

Micros
  • 5,966
  • 2
  • 28
  • 34
  • Thx, actually I accepted and gave a bounty to the Vic's answer for a plugin he created to resolve the problem, which is linked at the end of his answer. – biesior Apr 08 '16 at 09:49
  • 5
    Yep, I saw that. It is well deserved. But for some people simply doing this search might be a much quicker solution that installing a plugin. – Micros Apr 08 '16 at 09:53
  • i used this in a php script to make very well formatted HTML content for migration into WordPress: `$string = preg_replace( '/[^\x00-\x7F]/', null, $string ); htmlspecialchars_decode( htmlentities( html_entity_decode( $string ) ) );` – aequalsb Feb 21 '17 at 13:59