sublimehq / sublime_text

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

Pasted text containing NULLs is truncated #393

Closed bdlow closed 4 years ago

bdlow commented 10 years ago

Pasting text that includes NULL characters shows up in Sublime 3 truncated at the first NULL.

Operating System: OSX 10.9.4 The version of Sublime Text: Build 3059 Any related software which may cause ST to act strangely: none, known

Repro: % echo "one\0two\0three" | pbcopy

FichteFoll commented 10 years ago

@bdlow previously commented (now deleted):

If Sublime inserts NUL's sporadically under certain conditions, and without knowing we save, the next time we open the file will be truncated, if we then unwittingly save again, we've potentially lost a lot of work.


So, you are saying that ST truncates files with NUL bytes when opening them? That'd be a different issue and definitely critical.

bdlow commented 10 years ago

I hadn't tried opening a file containing NULs - I just did, and it's kinda weird. Sublime does NOT truncate the file, but it also doesn't open it as a regular text file.

Sublime presents the file contents as a hexdump, but editable as a text file. ~% echo "one\0two\0three" > /tmp/n.txt ~% subl -n /tmp/n.txt

Sublime shows as a hexdump: 6f6e 6500 7477 6f00 7468 7265 650a

The text is editable in some sort of weird mashup of a hex editor and text editor. Attempting to edit the file in this mode gives unpredictable results. This mode seems totally useless - presenting a hexdump without the actual structure of a hex editor is not very helpful. Seems like the far more sensible thing to do would be to present NULs as ^@.

FichteFoll commented 10 years ago

Yes, that is expected or intended behavior. ST opens files with unprintable characters (like control characters <0x20) in hex mode. The built-in hex viewer is not really good, but at least there is a plugin that does it better.

Anyway, what I was confused about is this:

If Sublime inserts NUL's sporadically under certain conditions, and without knowing we save, the next time we open the file will be truncated, if we then unwittingly save again, we've potentially lost a lot of work.

qgates commented 9 years ago

Anyway, what I was confused about is this:

If Sublime inserts NUL's sporadically under certain conditions, and without knowing we save, the next time we open the file will be truncated, if we then unwittingly save again, we've potentially lost a lot of work.

That pertains to the how this issue pertained to the related thread. I've deleted the comment as I'd overlooked that this issue related to pasting and not opening. My bad.

FichteFoll commented 9 years ago

Hm, now this whole discussion is ripped out of context. Tried my best.

qgates commented 9 years ago

Didn't see much point leaving it in; it's no longer relevant to this thread. Apologies for any confusion.

To clarify, I've just tested and Sublime does not truncate files when opening. Behaviour seems dependent on the file and where the NUL chars exist; sometimes Sublime opens them as hex and sometimes it opens them as text with embedded NUL characters.

evandrocoan commented 7 years ago

Also copying text containing NULL's is truncated after the first nul: test3_log.txt

back

BenjaminSchaaf commented 4 years ago

We've got a fix for this in the pipeline

BenjaminSchaaf commented 4 years ago

Fixed in 4075