sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
807 stars 39 forks source link

Random `NUL` control character. #476

Closed jedkirby closed 7 years ago

jedkirby commented 10 years ago

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

MattDMo commented 10 years ago

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

hi-im-si commented 10 years ago

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

MattDMo commented 10 years ago

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.

hi-im-si commented 10 years ago

Many thanks. Will keep you updated on this.

jedkirby commented 10 years ago

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

FichteFoll commented 10 years ago

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.

hi-im-si commented 10 years ago

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

brett-chisholm commented 10 years ago

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

mitchward commented 10 years ago

@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.

MattDMo commented 10 years ago

@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...

mitchward commented 10 years ago

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!

FichteFoll commented 10 years ago

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

qgates commented 10 years ago

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.

PropTim commented 7 years ago

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

FichteFoll commented 7 years ago

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

jedkirby commented 7 years ago

@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 ..

keith-hall commented 7 years ago

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

wbond commented 7 years ago

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

wbond commented 7 years ago

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.

xploSEoF commented 6 years ago

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:

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:

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.

keith-hall commented 6 years ago

seems like https://github.com/SublimeTextIssues/Core/issues/1303 is related then, and for the mac issues, maybe the files were being saved to an smb share: https://github.com/SublimeTextIssues/Core/issues/1332