Hi!

On Fri, 2024-06-07 at 15:40:07 +0200, Alexandre Detiste wrote:
> Maybe a compromise would be to at least mandate some UTF-8 locale.

Ah, good thinking! That would actually seem acceptable. I've prepared
the attached preliminary patch (missing better commit message, etc),
as a PoC for how this could look like. If there's consensus about
something like this, I'd be happy to merge into a future dpkg release.

Although I'm not sure though whether this would be enough to make it
possible to remove the hardcoding of LC_ALL=C.UTF-8 usage in debhelper,
which seems counter to l10n work, or perhaps to switch to a subset of
the locale settings. Niels?

Thanks,
Guillem
From 94c2540fe290ffaa70680d21725e3541642ab2f2 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guil...@debian.org>
Date: Tue, 2 Jul 2024 03:34:35 +0200
Subject: [PATCH] dpkg-buildpackage: Require an UTF-8 (or ASCII) locale when
 building packages

Proposed-by: Alexandre Detiste <alexandre.deti...@gmail.com>
---
 scripts/dpkg-buildpackage.pl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index df2edded9..3f02f81ca 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -27,6 +27,7 @@ use File::Temp qw(tempdir);
 use File::Basename;
 use File::Copy;
 use File::Glob qw(bsd_glob GLOB_TILDE GLOB_NOCHECK);
+use I18N::Langinfo qw(langinfo CODESET);
 use POSIX qw(:sys_wait_h);
 
 use Dpkg ();
@@ -589,6 +590,19 @@ if ($signsource && build_has_none(BUILD_SOURCE)) {
 if ($sanitize_env) {
     run_vendor_hook('sanitize-environment');
 }
+my %allow_codeset = map { $_ => 1 } qw(
+    UTF-8
+    ANSI_X3.4-1968
+    ANSI_X3.4-1986
+    ISO646-US
+    ASCII
+    US-ASCII
+);
+
+my $codeset = langinfo(CODESET);
+if (not exists $allow_codeset{$codeset}) {
+    error(g_('requires a locale with a UTF-8 (or ASCII) codeset'));
+}
 
 my $build_driver = Dpkg::BuildDriver->new(
     ctrl => $ctrl,
-- 
2.45.2

Reply via email to