From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#31149: 27.0.50; (gui-get-selection nil 'text/html) returns mis-decoded text Date: Sat, 14 Apr 2018 09:32:41 +0300 Message-ID: <83vacu47sm.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1523687534 16516 195.159.176.226 (14 Apr 2018 06:32:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Apr 2018 06:32:14 +0000 (UTC) Cc: larsi@gnus.org, 31149@debbugs.gnu.org To: Stefan Monnier , Kenichi Handa Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 14 08:32:09 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7EjI-000496-Iw for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Apr 2018 08:32:08 +0200 Original-Received: from localhost ([::1]:36411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7ElO-0007ob-Ub for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Apr 2018 02:34:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7ElC-0007nI-7e for bug-gnu-emacs@gnu.org; Sat, 14 Apr 2018 02:34:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f7El8-0004nj-9K for bug-gnu-emacs@gnu.org; Sat, 14 Apr 2018 02:34:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43390) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f7El8-0004ne-5z for bug-gnu-emacs@gnu.org; Sat, 14 Apr 2018 02:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1f7El8-00048C-0E for bug-gnu-emacs@gnu.org; Sat, 14 Apr 2018 02:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Apr 2018 06:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31149 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31149-submit@debbugs.gnu.org id=B31149.152368759815828 (code B ref 31149); Sat, 14 Apr 2018 06:34:01 +0000 Original-Received: (at 31149) by debbugs.gnu.org; 14 Apr 2018 06:33:18 +0000 Original-Received: from localhost ([127.0.0.1]:51287 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7EkN-00047B-6D for submit@debbugs.gnu.org; Sat, 14 Apr 2018 02:33:18 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56266) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7EkH-00046u-SC for 31149@debbugs.gnu.org; Sat, 14 Apr 2018 02:33:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f7Ek8-0004Qy-RC for 31149@debbugs.gnu.org; Sat, 14 Apr 2018 02:33:04 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43386) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7Ejr-0004M7-M9; Sat, 14 Apr 2018 02:32:43 -0400 Original-Received: from [176.228.60.248] (port=3659 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1f7Ejq-0003dN-56; Sat, 14 Apr 2018 02:32:42 -0400 In-reply-to: (message from Stefan Monnier on Fri, 13 Apr 2018 16:55:26 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:145324 Archived-At: > From: Stefan Monnier > Date: Fri, 13 Apr 2018 16:55:26 -0400 > Cc: Lars Ingebrigtsen > > (gui-get-selection nil 'text/html) > > returns utf-16 text when the primary selection is owned by Mozilla, but > we decode it as latin-1 instead, so it looks like garbage. > > I don't know why we're getting utf-16. Is that what standards say it > should do? If so, we should adjust our code (which currently knows > nothing about the `text/html` target-type). > > As for why we decode it as latin-1, it's (under GNU/Linux; Lars may be > using something else because he's getting something with a `charset` > property which I don't get here) because: > - selection_data_to_lisp_data (in xselect.c) makes a unibyte string with > the property `foreign-selection` set to `STRING` when the actual > string type is not known (as opposed to COMPOUND-TEXT and > UTF8-STRING, basically). > - in gui-get-selection we then have a mapping from `STRING` to > `iso-8859-1` (which is apparently the right thing for the official > `STRING` target-type in X11). > > I can't figure out if/where these kinds of things about the X11 > selection protocol is described, but at least in `xclip` they have > a hack specifically for this case: > > [...] > if (html != None && sel_type == html) { > /* if the buffer contains UCS-2 (UTF-16), convert to > * UTF-8. Mozilla-based browsers do this for the > * text/html target. > */ > [...] > > and according to the subsequent code it's not even always the > same endianness. > > I don't know what is the difference between the `target-type` passed to > x-get-selection-internal and the `foreign-selection` property we get on > the returned string (they seem to be the same in my tests, except when > the type is not one of the known ones, and where we then force > `foreign-selection` to be `STRING`). I Hope Handa-san (CC'ed) could comment on this.