Bug#242927: Gtranslator crashes when saving file with Hebrew chars
Loïc Minier
Loïc Minier ,
242927@bugs.debian.org
Sat, 29 Jan 2005 00:32:03 +0100
--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
tags 242927 + patch pending
thanks
Hi,
Your problem has been fixed and an upload should come soon. Attached
is a patch fixing the problem.
Regards,
--=20
Lo=EFc Minier <lool@dooz.org>
"Neutral President: I have no strong feelings one way or the other."
--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gtranslator-1.1.5_content-type-parsing.patch"
#! /bin/sh /usr/share/dpatch/dpatch-run
## 99-unnamed.dpatch by Loic Minier <lool@dooz.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.
@DPATCH@
--- gtranslator-1.1.5.orig/src/header_stuff.c
+++ gtranslator-1.1.5/src/header_stuff.c
@@ -146,15 +146,43 @@
if_key_is("Content-Type") {
gchar *prefix;
- prefix = strstr (pair[1], "text/plain; charset=");
- if (prefix)
- ph->charset = g_strdup (prefix + 20);
+ /* check whether we've got "text/plain" */
+ prefix = strstr (pair[1], "text/plain");
+ if ((! prefix) || prefix != pair[1])
+ {
+ g_warning("Content-Type doesn't start with text/plain (got '%s')", pair[1]);
+ }
+ /* search for a "charset=" parameter */
+ /* (note that we're cool since we allow other params
+ * to be passed too!) */
+ prefix = strstr (pair[1], "; charset=");
+ if (prefix) {
+ /* we should check for allowed charsets --
+ * a complete list can be found in section 5.2,
+ * Filling in the Header Entry, in the gettext
+ * manual -- and default to detecting the
+ * encoding */
+ ph->charset = g_strdup (prefix + 10);
+ }
else
- ph->charset = g_strdup (pair[1]);
+ {
+ /* no "charset=" parameter
+ * gtranslator used to default to pair[1].
+ * The best thing to do would be to detect
+ * the encoding, but frankly people should
+ * simply put a charset */
+ g_warning("Content-Type has no charset parameter (got '%s'), defaulting to UTF-8", pair[1]);
+ /* we g_strdup() it so it can be freed
+ * transparently */
+ ph->charset = g_strdup ("UTF-8");
+ }
}
else
if_key_is("Content-Transfer-Encoding")
- ph->encoding = g_strdup(pair[1]);
+ {
+ /* we should warn for anything else than "8-bit" */
+ ph->encoding = g_strdup(pair[1]);
+ }
else
if_key_is("Plural-Forms")
--AqsLC8rIMeq19msA--