[Webkit-unassigned] [Bug 55270] New: HTML 5 drag and drop uses incorrect text encoding

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Feb 25 15:13:04 PST 2011


https://bugs.webkit.org/show_bug.cgi?id=55270

           Summary: HTML 5 drag and drop uses incorrect text encoding
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Macintosh
        OS/Version: Mac OS X 10.6
            Status: UNCONFIRMED
          Severity: Major
          Priority: P2
         Component: WebKit Qt
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: phoenix1701 at gmail.com


Affected Platforms:
Mac OS X 10.6 (at least -- haven't tested on other platforms).

Reproduction:
Write the following JavaScript code in an element's onDragBegin event handler:

  evt.effectAllowed = 'copy';
  evt.dataTransfer.setData('text/plain', 'Hello, world!');

Render the element in a QWebView.

Now, drag the element into another application (like a text editor).  When dropped, the single character "H" will be displayed in the text editor.

Drag the element again, this time into a QLineEdit within the same application.  When dropped, the string "H e l l o ,   w o r l d !" will be displayed in the QLineEdit.

Cause:
The string is encoded in UTF-16 (likely because JavaScript encodes all strings as UTF-16), but the pasteboard is expecting UTF-8.  QtWebKit does not seem to perform the conversion when the drag data is copied to the pasteboard, so the net effect is that (for plain ASCII text like "Hello, world!") the data is interspersed with NULL bytes.  This causes most implementations to truncate after the first character; within the same application, though, the length information is preserved, and so the NULLs are rendered as spaces.

Workaround:
You can partially work around the bug for within-application drops by manually reinterpreting the data as UTF-16, like so:

  QByteArray text = mimeData->data("text/plain");
  const char* utf16 = text.constData();
  QString real_text = QString::fromUtf16(reinterpret_cast<const ushort*>(utf16), text.length() / 2);

Suggested Fix:
Convert strings coming from JavaScript to UTF-8 before copying them to the pasteboard.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list