From 2aedeb8c8460e2773d623cba738efc511c251cd3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 22 Jul 2025 19:19:17 +0200 Subject: [PATCH] fix UTF-8 detection 1 --- tests/runtests.pl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/runtests.pl b/tests/runtests.pl index 23736f2ac5..0361e2b31a 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -83,6 +83,7 @@ BEGIN { use Digest::MD5 qw(md5); use List::Util 'sum'; use I18N::Langinfo qw(langinfo CODESET); +use POSIX qw(setlocale LC_ALL); use serverhelp qw( server_exe @@ -484,6 +485,25 @@ sub parseprotocols { push @protocols, 'none'; } +####################################################################### +# Check if the operating environment supports UTF-8. +sub is_utf8_supported { + my $result; + my $old_LC_ALL; + my $was_defined = defined $ENV{'LC_ALL'}; + if($was_defined) { + $old_LC_ALL = $ENV{'LC_ALL'}; + } + setlocale(LC_ALL, $ENV{'LC_ALL'} = 'en_US.UTF-8'); + $result = lc(langinfo(CODESET())) eq "utf-8"; + if($was_defined) { + $ENV{'LC_ALL'} = $old_LC_ALL; + } + else { + delete $ENV{'LC_ALL'}; + } + return $result; +} ####################################################################### # Check & display information about curl and the host the test suite runs on. @@ -808,7 +828,7 @@ sub checksystemfeatures { # Use this as a proxy for any cryptographic authentication $feature{"crypto"} = $feature{"NTLM"} || $feature{"Kerberos"} || $feature{"SPNEGO"}; $feature{"local-http"} = servers::localhttp(); - $feature{"codeset-utf8"} = lc(langinfo(CODESET())) eq "utf-8"; + $feature{"codeset-utf8"} = is_utf8_supported(); if($feature{"codeset-utf8"}) { $ENV{'CURL_TEST_HAVE_CODESET_UTF8'} = 1; }