git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Justin Tobler <jltobler@gmail.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	 git@vger.kernel.org, Taylor Blau <me@ttaylorr.com>,
	 Yi EungJun <eungjun.yi@navercorp.com>
Subject: Re: [PATCH 1/1] http: don't send C or POSIX in Accept-Language
Date: Fri, 11 Jul 2025 11:32:19 -0700	[thread overview]
Message-ID: <xmqqldou1suk.fsf@gitster.g> (raw)
In-Reply-To: <r34i7fhxwbxhppc4ia7lpyr3xqj4tgusaeikaaonpwtywlywxw@ygfmv3f3q67u> (Justin Tobler's message of "Fri, 11 Jul 2025 10:23:38 -0500")

Justin Tobler <jltobler@gmail.com> writes:

> Looking at `get_preferred_languages()` when NO_GETTEXT is defined, we
> already filter out "C" and "POSIX". So doing this for the LANGUAGE
> environment variable when writing the header also makes sense.

True.  I wonder if it makes sense to do the check in that helper
function, though.  I.e. something like

diff --git c/gettext.c w/gettext.c
index 8d08a61f84..e2e0fe339d 100644
--- c/gettext.c
+++ w/gettext.c
@@ -41,6 +41,16 @@ static const char *locale_charset(void)
 
 static const char *charset;
 
+static const char *filter_out_non_languages(const char *candidate)
+{
+	if (candidate && *candidate &&
+	    strcmp(candidate, "C") &&
+	    strcmp(candidate, "POSIX"))
+		return candidate;
+	else
+		return NULL;
+}
+
 /*
  * Guess the user's preferred languages from the value in LANGUAGE environment
  * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
@@ -51,15 +61,13 @@ const char *get_preferred_languages(void)
 {
 	const char *retval;
 
-	retval = getenv("LANGUAGE");
-	if (retval && *retval)
+	retval = filter_out_non_languages(getenv("LANGUAGE"));
+	if (retval)
 		return retval;
 
 #ifndef NO_GETTEXT
-	retval = setlocale(LC_MESSAGES, NULL);
-	if (retval && *retval &&
-		strcmp(retval, "C") &&
-		strcmp(retval, "POSIX"))
+	retval = filter_out_non_languages(setlocale(LC_MESSAGES, NULL));
+	if (retval)
 		return retval;
 #endif
 

In the production code, we should have a comment before that new
helper function that explains why we exclude C and POSIX, if we were
to go that route.

> Not sure if being more strict adds much more value here in practice
> though. So it may be fine to keep it as-is. :)

Yup.  I care more about having a single place that checks using the
same logic, than what that logic exactly is ;-).

Thanks.

  parent reply	other threads:[~2025-07-11 18:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-10 22:16 [PATCH 0/1] Filter C and POSIX out of Accept-Language brian m. carlson
2025-07-10 22:16 ` [PATCH 1/1] http: don't send C or POSIX in Accept-Language brian m. carlson
2025-07-10 22:47   ` Junio C Hamano
2025-07-10 23:08     ` brian m. carlson
2025-07-11 15:23   ` Justin Tobler
2025-07-11 17:02     ` Collin Funk
2025-07-11 20:57       ` Carlo Marcelo Arenas Belón
2025-07-11 21:29         ` brian m. carlson
2025-07-11 22:12           ` Carlo Arenas
2025-07-11 22:17             ` Collin Funk
2025-07-11 18:32     ` Junio C Hamano [this message]
2025-07-11 20:22       ` Carlo Marcelo Arenas Belón
2025-07-15  4:38   ` Eli Schwartz
2025-07-10 22:45 ` [PATCH 0/1] Filter C and POSIX out of Accept-Language Junio C Hamano
2025-07-10 23:08   ` brian m. carlson
2025-07-10 23:26     ` Collin Funk
2025-07-11  2:49       ` [External] " Han Young
2025-07-11 16:46         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqldou1suk.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=eungjun.yi@navercorp.com \
    --cc=git@vger.kernel.org \
    --cc=jltobler@gmail.com \
    --cc=me@ttaylorr.com \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).