GNOME Bugzilla – Bug 156423
Saving in UTF-16 encoding destroys files
Last modified: 2005-01-25 19:03:43 UTC
1. Create a file of some length (a sentence for example) with gedit 2. Make sure the UTF-16 charset is available in the Save as dialog 3. Save as UTF-16 4. Check the saved file, it's 2 chars long Reported against 2.6, also happens in 2.8. This is Debian bug <http://bugs.debian.org/261622>. Regards, -- Loïc Minier
I can reproduce this bug on Fedora Core 2 too.
This is due to the fact that UTF-16 encoded text may contain 0x00 bytes. So the following code in gedit-document.c (gedit_document_save_as_real function) is wrong: if (encoding != gedit_encoding_get_utf8 ()) { GError *conv_error = NULL; gchar* converted_file_contents = NULL; converted_file_contents = gedit_convert_from_utf8 (chars, -1, encoding, &conv_error); if (conv_error != NULL) { /* Conversion error */ g_propagate_error (error, conv_error); close (fd); unlink (temp_filename); goto out; } else { g_free (chars); chars = converted_file_contents; } } chars_len = strlen (chars); add_cr = (*(chars + chars_len - 1) != '\n'); /* Save the file content */ res = (write (fd, chars, chars_len) == chars_len); if (res && add_cr) /* Add \n if needed */ res = (write (fd, "\n", 1) == 1); The only way I see to solve this problem is to modify gedit_convert_from_utf8 so that it returns the length in bytes of the converted text. Note that we must add the closing "\n" before converting the text to the new encoding.
*** Bug 156130 has been marked as a duplicate of this bug. ***
is this a related (dup?) of http://bugzilla.gnome.org/show_bug.cgi?id=126555
no, it isn't.
Created attachment 36509 [details] [review] Patch against CVS HEAD The attached patch solves the problem. It is still not ready to be committed since it breaks the savecopy plugin and needs some polishment too.
Created attachment 36511 [details] [review] patch just comipile tested
Created attachment 36513 [details] [review] Patch against CVS HEAD (v.2) This patch merges the previous two patches and fixed a couple of problems.
Created attachment 36515 [details] [review] Committed patch
Fixed in CVS HEAD.