From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#51832: Piping unicode text in `shell-command' Date: Sun, 14 Nov 2021 15:20:14 +0000 Message-ID: References: <83k0hbuosm.fsf@gnu.org> <87h7cf84l1.fsf@gnus.org> <87czn383z6.fsf@gnus.org> <83h7cfuixu.fsf@gnu.org> <9EB4417D-2457-46AD-9198-E42BBAF11071@gmail.com> <83czn3uhtd.fsf@gnu.org> <87v90u7t2l.fsf@gnus.org> <44FDC8DA-6F3B-4896-B019-D98A9E7D72E7@gmail.com> <87pmr27qx9.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="gGwfOvpY0P3Vgaxz" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39747"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 51832@debbugs.gnu.org, Philipp , tor.a.s.kringeland@ntnu.no To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 14 16:21:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmHJi-000A8l-1r for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Nov 2021 16:21:14 +0100 Original-Received: from localhost ([::1]:37964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmHJg-0000bl-QJ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Nov 2021 10:21:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmHJX-0000Z9-BE for bug-gnu-emacs@gnu.org; Sun, 14 Nov 2021 10:21:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmHJX-0002vl-2D for bug-gnu-emacs@gnu.org; Sun, 14 Nov 2021 10:21:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmHJW-0002q4-Uh for bug-gnu-emacs@gnu.org; Sun, 14 Nov 2021 10:21:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Nov 2021 15:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51832 X-GNU-PR-Package: emacs Original-Received: via spool by 51832-submit@debbugs.gnu.org id=B51832.163690322910836 (code B ref 51832); Sun, 14 Nov 2021 15:21:02 +0000 Original-Received: (at 51832) by debbugs.gnu.org; 14 Nov 2021 15:20:29 +0000 Original-Received: from localhost ([127.0.0.1]:51347 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmHIz-0002oi-24 for submit@debbugs.gnu.org; Sun, 14 Nov 2021 10:20:29 -0500 Original-Received: from outbound.soverin.net ([116.202.126.228]:45317) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmHIx-0002oS-4N for 51832@debbugs.gnu.org; Sun, 14 Nov 2021 10:20:27 -0500 Original-Received: from smtp.soverin.net (unknown [10.10.3.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 3AD118A1; Sun, 14 Nov 2021 15:20:21 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.138]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1636903219; bh=mdaSFkki3HU5ZNM8dEfil0lZd2KFzEt+315zWWe9wrI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bsxatHsfQJGaL/9fUdiJFvGATZ4No6whfLOO7B3xfB2sSVSpDNkffDm/jwb4VbNPY e1Qvd8htzFvSyAoEQYkJzthn+Y0z24pFgFVKpWk1eJhH81NDccEqAMfB42scNfe3jw ri9wyYntDzwI3a7Z1qWl54jHCeBIy/uWGD2YJHZILRhLl2fMxJYUI4+1/OYiTnb279 sZYUaYWNzx6p1br/zpXGBbFdzQ6JMzN9ImwwPZJ0400P9orLTeZHtk20bOm4/UxHXn hJvqaDR5uIQ0aUOL7r8UwL+r0gqgRLnyy1Pi3Fuxy5bQr24cv65s/Thv2sO6gvjPpI qkUBVf+hJwGaA== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id B81A5202DAFC61; Sun, 14 Nov 2021 15:20:14 +0000 (GMT) Mail-Followup-To: Alan Third , Lars Ingebrigtsen , Philipp , Eli Zaretskii , tor.a.s.kringeland@ntnu.no, 51832@debbugs.gnu.org Content-Disposition: inline In-Reply-To: <87pmr27qx9.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219953 Archived-At: --gGwfOvpY0P3Vgaxz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Nov 14, 2021 at 03:28:02PM +0100, Lars Ingebrigtsen wrote: > Philipp writes: > > >> That didn't fix the issue for me, I'm afraid -- with that patch, LANG is > >> still the invalid en_NO.UTF-8 for me. > > > > Maybe we should add similar logic as iTerm2 I tried to find how iTerm2 does it. Your search-fu is better than mine, apparently. :) > > (https://github.com/gnachman/iTerm2/blob/79aff4d59fd591e7628649bcabe5f27541740bf6/sources/PTYSession.m#L7107): > > create the locale identifier from language code and country code > > instead of the current locale identifier, > > I think that's what's Macos is returning -- it's just concatenating > those two codes to get a locale identifier. (Which is wrong, of > course.) Yeah, I don't think there's any advantage to building them up manually. > > and use setlocale (or better, newlocale) to check whether it's valid, > > Yes, that sounds good. > > > and fall back to en_US.UTF-8 otherwise? > > Hm... I'd rather just leave LANG unset in that case -- it'll probably > lead to fewer glitches, I think. I proposed something similar before: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=51321#90 but it didn't look like we needed it then. We know better now. New patch attached. -- Alan Third --gGwfOvpY0P3Vgaxz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Only-set-LANG-if-the-ID-is-valid.patch" >From 3a2e20c659d8732b11d30cdb27e36610e87a0315 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sun, 14 Nov 2021 15:09:43 +0000 Subject: [PATCH v2] Only set LANG if the ID is valid * src/nsterm.m (ns_init_locale): Check the provided locale identifier is available before trying to use it. --- src/nsterm.m | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/nsterm.m b/src/nsterm.m index 1f17a30272..983e5eb8ac 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -535,21 +535,18 @@ - (NSColor *)colorUsingDefaultColorSpace NSTRACE ("ns_init_locale"); - @try + if (!isatty (STDIN_FILENO)) { - /* It seems macOS should probably use UTF-8 everywhere. - 'localeIdentifier' does not specify the encoding, and I can't - find any way to get the OS to tell us which encoding to use, - so hard-code '.UTF-8'. */ + char *oldLocale = setlocale (LC_ALL, NULL); NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8", [locale localeIdentifier]]; - /* Set LANG to locale, but not if LANG is already set. */ - setenv("LANG", [localeID UTF8String], 0); - } - @catch (NSException *e) - { - NSLog (@"Locale detection failed: %@: %@", [e name], [e reason]); + /* Check the locale ID is valid and if so set LANG, but not if + it is already set. */ + if (setlocale (LC_ALL, [localeID UTF8String])) + setenv("LANG", [localeID UTF8String], 0); + + setlocale (LC_ALL, oldLocale); } } -- 2.32.0 --gGwfOvpY0P3Vgaxz--