After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 382824 - Dragging non-ascii text from gecko to GtkEntry sometimes inserts invalid UTF-8
Dragging non-ascii text from gecko to GtkEntry sometimes inserts invalid UTF-8
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-12-05 23:53 UTC by Björn Lindqvist
Modified: 2007-04-15 16:00 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Björn Lindqvist 2006-12-05 23:53:05 UTC
Steps:

1. Select some text containing non-ASCII characters.
2. Drag that text selection to a GtkEntry.

Observe how all non-ASCII characters are replaced with "?". When doing this on Epiphany it says:

(epiphany:2589): Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()

(epiphany:2589): GLib-CRITICAL **: g_utf8_casefold: assertion `str != NULL' failed

But it must be a GTK bug because I can reproduce it on any GtkEntry.
Comment 1 Christian Persch 2006-12-06 13:47:58 UTC
Confirming with testentrycompletion by dragging text from epiphany.

(lt-testentrycompletion:23228): Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()

Trace:
  • #0 g_log
  • #1 pango_layout_set_text
    at pango-layout.c line 886
  • #2 gtk_entry_ensure_layout
    at gtkentry.c line 3246
  • #3 gtk_entry_adjust_scroll
    at gtkentry.c line 3677
  • #4 recompute_idle_func
    at gtkentry.c line 3083
  • #5 g_idle_dispatch
    at gmain.c line 4073
  • #6 g_main_context_dispatch
    at gmain.c line 2049
  • #7 g_main_context_iterate
    at gmain.c line 2681
  • #8 g_main_loop_run
    at gmain.c line 2885
  • #9 gtk_main
    at gtkmain.c line 1148
  • #10 main
    at testentrycompletion.c line 448

dnd-list shows the following targets offered:
text/_moz_htmlcontext
text/_moz_htmlinfo
text/html
text/unicode
text/plain
Comment 2 Yevgen Muntyan 2007-04-13 15:31:26 UTC
It works fine in gtk-demo's Entry Completion and in xchat, when dragging Russian text. What text do you need to reproduce it?
Comment 3 Christian Persch 2007-04-13 17:47:59 UTC
Still reproducible here with gtk+ svn trunk. 

Using this bug report in epiphany as source, I dragged the text "Björn" from commenter 0's name to any gtkentry or gtktextview in another application. (The critical comes from the target application, not from epiphany.)
Comment 4 Yevgen Muntyan 2007-04-13 19:40:30 UTC
Got it, you need to drag text from mozilla (and I tried from gtktextview first). So it's not just "non-ASCII and GtkEntry", it has to do with source too.
Comment 5 Christian Persch 2007-04-13 20:20:20 UTC
Well, there might be a bug in the source too, but definitely gtk shouldn't insert invalid UTF-8 that was dragged into entries.
Comment 6 Yevgen Muntyan 2007-04-13 21:43:57 UTC
When you drag that ö from mozilla to gtk, selection_get_text_plain() in gtkselection.c calls g_convert_with_fallback("\xc3\xb6", "ISO-8859-1", "UTF-8") which returns "\xf6" which is not valid UTF-8. So it's a glib bug (or glibc?).
Comment 7 Yevgen Muntyan 2007-04-13 22:24:14 UTC
Nevermind, the real problem was apparently copy/paste. Fix:

Index: gtk/gtkselection.c
===================================================================
--- gtk/gtkselection.c  (revision 17599)
+++ gtk/gtkselection.c  (working copy)
@@ -1310,7 +1310,7 @@ selection_get_text_plain (GtkSelectionDa
     {
       gchar *tmp = str;
       str = g_convert_with_fallback (tmp, len,
-                                    charset, "UTF-8",
+                                    "UTF-8", charset,
                                     NULL, NULL, &len, &error);
       g_free (tmp);
Comment 8 Tim Janik 2007-04-14 15:43:38 UTC
(In reply to comment #7)
> Nevermind, the real problem was apparently copy/paste. Fix:
> 
> Index: gtk/gtkselection.c
> ===================================================================
> --- gtk/gtkselection.c  (revision 17599)
> +++ gtk/gtkselection.c  (working copy)
> @@ -1310,7 +1310,7 @@ selection_get_text_plain (GtkSelectionDa
>      {
>        gchar *tmp = str;
>        str = g_convert_with_fallback (tmp, len,
> -                                    charset, "UTF-8",
> +                                    "UTF-8", charset,
>                                      NULL, NULL, &len, &error);
>        g_free (tmp);

patch looks fine, please apply+test+commit with appropriate changelog.
Comment 9 Yevgen Muntyan 2007-04-14 16:05:41 UTC
Committed (I can't close this bug).
There is another bug: when you drag that Bjoern to a gtk entry, it inserts some nonsense instead of fancy o with dots. But that's a different problem, about what text/plain is supposed to contain and how to treat it.
Comment 10 Murray Cumming 2007-04-14 16:31:45 UTC
I hesitate to close this bug before that other bug is opened.
Comment 11 Yevgen Muntyan 2007-04-14 17:58:23 UTC
See #429738.
Comment 12 Owen Taylor 2007-04-15 15:29:26 UTC
So, what's the mozilla bug about it not offering UTF8_STRING, which
is the *only* target that I'm aware of that actually is well defined
as to encoding?