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 649390 - CRLF text is copied to clipboard as CRCRLF on Windows
CRLF text is copied to clipboard as CRCRLF on Windows
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Win32
unspecified
Other Windows
: Normal normal
: ---
Assigned To: Aleksander Morgado
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2011-05-04 16:27 UTC by Bart Jacobs
Modified: 2013-06-18 12:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Repro in O'Caml (322 bytes, application/octet-stream)
2011-05-04 16:27 UTC, Bart Jacobs
  Details
C# program to show the contents of the clipboard (655 bytes, text/plain)
2011-05-04 16:30 UTC, Bart Jacobs
  Details
C# program for setting the contents of the clipboard (314 bytes, text/plain)
2011-05-04 16:31 UTC, Bart Jacobs
  Details
Patch for the issue. (1.18 KB, patch)
2013-02-27 08:24 UTC, Aleksander Morgado
committed Details | Review

Description Bart Jacobs 2011-05-04 16:27:28 UTC
Created attachment 187214 [details]
Repro in O'Caml

Copying text containing CRLF line endings to the clipboard is broken in the current Windows port. For example, copying "Hello\r\nBye" using gtk_clipboard_set_text results in the text "Hello\r\r\nBye" on the clipboard.
The general phenomenon is that GTK/GDK replaces LFs by CRLFs, and it copies existing CRs as-is.

Repro
=====
- Run the O'Caml program clipboard_test.ml in attach.
- Run the C# program get_clipboard.cs in attach. The output is incorrect.

As evidence that the problem is in GTK/GDK and not in Windows or C#:
- Run the C# program set_clipboard.cs in attach.
- Run the C# program get_clipboard.cs in attach. The output is correct.

Proposed Fix
============

I believe the problem could be solved easily if the LF-to-CRLF conversion code in function _gdk_win32_window_change_property in file gdk/win32/gdkproperty-win32.c were made more robust so that it would properly convert LF, CR, and CRLF line endings to CRLF.

Detailed Control Flow
=====================

gtk_clipboard_set_text
  gtk_clipboard_set_with_data(get_func=text_get_func)
    gtk_target_list_add_text_targets
      adds targets utf8_atom (="UTF8_STRING") and others
    gtk_clipboard_set_contents
      gtk_selection_owner_set_for_display
        gdk_selection_owner_set_for_display
          _gdk_win32_display_set_selection_owner
            gdk_event_put(type=GDK_SELECTION_REQUEST, target=_utf8_string (="UTF8_STRING", see gdk/win32/gdkmain-win32.c))
      gtk_selection_add_targets
        gdk_win32_selection_add_targets // Only relevant for delay-rendered formats

gtk_main
  g_main_loop_run
    ...
      gtk_main_do_event(event.type=GDK_SELECTION_REQUEST)
        gtk_widget_event
          gtk_widget_event_internal
            g_signal_emit(signal="selection-request-event")
              _gtk_selection_request
                gtk_selection_invoke_handler
                  g_signal_emit_by_name("selection-get", data, info)
                    "selection-get" event on clipboard widget
                       selection_get_cb (in gtk/gtkselection.c)
                         text_get_func
                           gtk_selection_data_set_text
                             gtk_selection_data_set
                gdk_property_change
                  _gdk_win32_window_change_property (in gdk/win32/gdkproperty-win32.c)
                     SetClipboardData(CF_UNICODETEXT, lf2crlf(data))

There are a number of places in gdk/win32/gdkselection-win32.c and gtk/gtkselection.c where the required conversions are done but these are not on the code path that results from a gtk_selection_set_text call.
Comment 1 Bart Jacobs 2011-05-04 16:30:33 UTC
Created attachment 187215 [details]
C# program to show the contents of the clipboard
Comment 2 Bart Jacobs 2011-05-04 16:31:11 UTC
Created attachment 187216 [details]
C# program for setting the contents of the clipboard
Comment 3 Aleksander Morgado 2013-02-27 08:24:19 UTC
Created attachment 237498 [details] [review]
Patch for the issue.
Comment 4 khronos 2013-06-02 17:28:32 UTC
Any reason why this stupidly annoying bug isn't fixed yet, even though it has a patch for such a long time?
Comment 5 khronos 2013-06-17 16:42:59 UTC
After much googling (I'm not a developer), I managed to cross-compile GTK with this fix applied and tested it on Windows 7. I can confirm that this patch does fix this particular problem.
Comment 6 Matthias Clasen 2013-06-17 17:15:45 UTC
thanks for testing !
Comment 7 Matthias Clasen 2013-06-17 17:17:08 UTC
Review of attachment 237498 [details] [review]:

lets get this in, then
Comment 8 Aleksander Morgado 2013-06-18 12:38:10 UTC
Pushed to gtk-2-24 and git master.

This problem has been fixed in our software repository. The fix will go into the next software release. Thank you for your bug report.