GNOME Bugzilla – Bug 695107
When document contains invalid characters, Save As is results in Save
Last modified: 2014-07-09 12:08:49 UTC
Created attachment 237936 [details] Text file to reproduce the bug Today I edited the attached /var/log/messages using gedit. When saving, gedit noticed that null characters were present, and that could likely corrupt the saved file. So far, so good. The problem is, even if I used File->Save As, gedit saved the file to the original location, which would have destroyed my system log (I know, gedit as root is total crack !). The point is, you try to do something very smart, and you end up destroying user data! Life is hard.
Comment on attachment 237936 [details] Text file to reproduce the bug Nevermind, saving it from gedit, I managed to lose these null characters. I guess you know how to recreate them... ;-)
Created attachment 258882 [details] File with invalid text I confirm the bug. I attach an invalid file.
In gedit-tab.c, _gedit_tab_save_as() calls gedit_document_save_as() with lots of parameters: location, encoding, newline type, compression type, and some flags. Then the document_saved() callback is called with the GEDIT_DOCUMENT_ERROR_CONVERSION_FALLBACK error. The info bar is created, and when we click on the Save Anyway button, the invalid_character_info_bar_response() callback is called. The latter calls gedit_document_save(), not gedit_document_save_as()... The problem: it seems that all the parameters for save_as() are not saved. There is tmp_save_location and tmp_encoding. But not for the others. It would be nice to setup an object with all the settings, and keep this object around, instead of copying the parameters.
This should be fixed in the git master branch, with the new file loading and saving code.