sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Random `NUL` control character.

Open jedkirby opened this issue 12 years ago • 21 comments

This seems to happen sporadically but every so often, a NUL control character will appear in my Sublime Text editor. The file types are not limited - so far it has appeared in .scss, .html, .php and .js files. Its particularly annoying when editing .scss files as it returns string errors in the command line when running a sass --watch and so breaks the SASS to CSS compiling. It is not always obvious, the watch error will be returned and i must close my source file and reopen to see the control character.

Image of NUL character

Mac OSX 10.9.4 ST 2 & 3

This is also listed on SO: http://stackoverflow.com/questions/25620049/sublime-text-returning-nul-control-character credit to @hi-im-si

jedkirby avatar Sep 11 '14 16:09 jedkirby

Are you copying and pasting from anywhere, or just typing everything in by hand? Is there a way to reliably reproduce this?

MattDMo avatar Sep 11 '14 16:09 MattDMo

Predominantly as a result of copying and pasting between files but not always. Its very sporadic and hard to reproduce an instance.

hi-im-si avatar Sep 11 '14 16:09 hi-im-si

Here is a plugin modified from my StackOverflow answer here. The original question was about finding zero-width space characters, but it should work just as well looking for NULs. The code below is specific for ST3, if you also want to run it on ST2, just change the method name from on_modified_async to on_modified.

import sublime_plugin


class ShowNULCharacters(sublime_plugin.EventListener):
    def on_modified_async(self, view):
        NULs = []
        p = 0
        while True:
            s = view.find('\u0000', p + 1)
            if not s:
                break
            NULs.append(s)
            p = s.a

        if NULs:
            view.add_regions("NUL", NULs, "invalid")
        else:
            view.erase_regions("NUL")

To use the plugin, create a new file in Sublime with Python syntax, and paste the code into it. Save it as Packages/User/show_nul_characters.py where Packages is the folder opened when you select Sublime Text -> Preferences -> Browse Packages... - on OS X it should be ~/Library/Application Support/Sublime Text 3/Packages. Once the file is saved, it should be loaded automatically and begin to work.

MattDMo avatar Sep 11 '14 16:09 MattDMo

Many thanks. Will keep you updated on this.

hi-im-si avatar Sep 11 '14 16:09 hi-im-si

Cheers for this @MattDMo - I'll give this a go too.

jedkirby avatar Sep 11 '14 16:09 jedkirby

And I was wondering why this looked so familiar.

However, afaik ST should display most of the control characters <0x20 with these boxes similar to "NUL" in the OP so I don't quite see how this is useful tbh.

FichteFoll avatar Sep 11 '14 20:09 FichteFoll

Unfortunately the fix @MattDMo suggested has not worked and these control characters are still showing and causing much havoc :(

hi-im-si avatar Sep 17 '14 12:09 hi-im-si

Likewise, @hi-im-si. Is this a, Sublime issue or something which happens sporadically in all text editors?

brett-chisholm avatar Sep 17 '14 13:09 brett-chisholm

@hi-im-si @btc90 @jedkirby As this issue seems contained within Propeller, I think it could be an issue with our workflow / server setup. Possibly, Sublime is writing the file to the server on save, reading it back quicker than it is written, and I imagine the NUL character is dumped where is reads to, then it continues to read the file. Similar to how you get that popup saying 'the file has changed on the server...' or whatever it says. Just a theory.

mitchward avatar Sep 19 '14 11:09 mitchward

@mitchward If you're working off a server, then by all means please set "atomic_save": false in your user settings. Atomic saving messes all sorts of things up...

MattDMo avatar Sep 19 '14 14:09 MattDMo

Thanks for the suggestion @MattDMo, we have put it in place and keep an eye on it. Having read up on atomic save, it seems it could have been the cause of another other issue we were having recently with a crazy amount of requests to the server whilst saving files. Hopefully this helps!

mitchward avatar Sep 19 '14 16:09 mitchward

I think we need a C: Atomic Save label ...

FichteFoll avatar Sep 19 '14 16:09 FichteFoll

I've seen sporadic NUL's appearing often when copying a single line to the clipboard (don't make a selection for the line, just place the cursor and hit ctrl+c), then making multiple cursors and pasting. The NUL appears at the 2nd cursor or beyond, and sometimes several.

I posted about this last year in the forum, and the issue affects ST2 as well as ST3 (<=3066).

Also related this issue in which another user describes the same bug pasting lines to multi-cursors.

Also I don't consider insertion of NUL's as minor since potentially it can garble source files without the user's knowledge.

qgates avatar Oct 17 '14 01:10 qgates

Is this bug anywhere close to being fixed? It's been open for well over 2 years >_<

PropTim avatar Jan 06 '17 12:01 PropTim

@PropTim considering that nobody could properly identify the underlying issue, no. Atomic saving is now disabled by default, however.

FichteFoll avatar Jan 10 '17 10:01 FichteFoll

@PropTim I think this might just be a Propeller-ism, as in, it must be something to do with the way files are edited there ..

jedkirby avatar Jan 10 '17 11:01 jedkirby

possible duplicate of https://github.com/SublimeTextIssues/Core/issues/1332

keith-hall avatar Feb 17 '17 13:02 keith-hall

@hi-im-si and @qgates I believe the bug is currently described at #1182 and should be fixed by the next dev build

wbond avatar May 24 '17 20:05 wbond

The issue with copy-paste inserting a NUL sometimes was fixed in 3132. It was caused when one or more complete lines was copied, and then pasted into a situation where there was one more cursor than the number of lines copied.

For example, copying one full line and pasting into two cursors would paste the line at the first cursor and NUL at the second.

wbond avatar May 26 '17 06:05 wbond

So, I've always had this issue in the back of my mind since my time at Propeller: we just couldn't fathom it from the data we had due to our understanding:

  • It only seemed to happen on a mac
  • it wasn't copy paste issues
  • it was incredibly hard to replicate
  • they don't show in sublime itself

However, I've had spurious null characters added by Sublime on Windows for the last year, and I think I've finally figured out more about when this happens.

I am currently not running a licensed version, so I get the prompt come up upon save every so often. Sometimes this prompt comes up behind windows, possibly because I'm quick with my keyboard shortcuts swapping around things.

Now for the kicker

Whilst this prompt is open (normally not seen), two weird things happen in the editor:

  • indentation of any additional lines goes a bit funky
  • NUL characters get inserted in random places if you continue working (I'm not too sure which keys trigger it)

This is almost as if something to do with this prompt is affecting how the editor handles the key bindings.

At Propeller, most of the developers on macs who used it at the time didn't have licenses (this may or may not have changed), and most would not be bothered by the indentation messing up, and the NUL characters would cause issues further down the road, not immediately.

This isn't the same as issue #1182 as they weren't visible in the editor at any point, which is why it caused such a problem at Propeller.

xploSEoF avatar Jul 04 '18 13:07 xploSEoF