diff options
author | Nicolas Williams <nico@cryptonector.com> | 2023-09-06 08:52:37 -0500 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-09-06 14:05:10 -0500 |
commit | 11c528d04d76c9b9553781aa76b073e4f40da008 (patch) | |
tree | 3eb4d21413cf215598675b4768d6afeb1f5d91ce | |
parent | ac3b70d3a118713b24a82da15441788fee6c5d4e (diff) |
Add setlocale() call (fix #1740)jq-1.7
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/main.c | 7 | ||||
-rwxr-xr-x | tests/shtest | 28 |
3 files changed, 31 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index 9e8830bf..4a724659 100644 --- a/configure.ac +++ b/configure.ac @@ -149,6 +149,7 @@ AC_CHECK_MEMBER([struct tm.tm_gmtoff], [AC_DEFINE([HAVE_TM_TM_GMT_OFF],1,[Define [], [[#include <time.h>]]) AC_CHECK_MEMBER([struct tm.__tm_gmtoff], [AC_DEFINE([HAVE_TM___TM_GMT_OFF],1,[Define to 1 if the system has the __tm_gmt_off field in struct tm])], [], [[#include <time.h>]]) +AC_FIND_FUNC([setlocale], [c], [#include <locale.h>], [0,0]) dnl Figure out if we have the pthread functions we actually need AC_FIND_FUNC_NO_LIBS([pthread_key_create], [], [#include <pthread.h>], [NULL, NULL]) @@ -2,6 +2,9 @@ #include <ctype.h> #include <errno.h> #include <libgen.h> +#ifdef HAVE_SETLOCALE +#include <locale.h> +#endif #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -319,6 +322,10 @@ int main(int argc, char* argv[]) { jv ARGS = jv_array(); /* positional arguments */ jv program_arguments = jv_object(); /* named arguments */ +#ifdef HAVE_SETLOCALE + (void) setlocale(LC_ALL, ""); +#endif + #ifdef WIN32 jv_tsd_dtoa_ctx_init(); fflush(stdout); diff --git a/tests/shtest b/tests/shtest index 52a82190..ee060e2e 100755 --- a/tests/shtest +++ b/tests/shtest @@ -2,6 +2,13 @@ . "${0%/*}/setup" "$@" +msys=false +mingw=false +case "$(uname -s)" in +MSYS*) msys=true;; +MINGW*) mingw=true;; +esac + JQ_NO_B=$JQ JQ="$JQ -b" @@ -496,11 +503,9 @@ cmp $d/color $d/expect cmp $d/warning $d/expect_warning # Check $NO_COLOR -case "$(uname -s)" in -MSYS*) test_no_color=false;; -MINGW*) test_no_color=false;; -*) test_no_color=true;; -esac +test_no_color=true +$msys && test_no_color=false +$mingw && test_no_color=false if $test_no_color && command -v script >/dev/null 2>&1; then unset NO_COLOR if script -qc echo /dev/null >/dev/null 2>&1; then @@ -561,4 +566,17 @@ if ! $VALGRIND $Q $JQ -n -f "$JQTESTDIR/yes-main-program.jq" > $d/out 2>&1; then exit 1 fi +if ( ! $msys && ! $mingw ) && locale -a > /dev/null; then + locale=$(locale -a | egrep -v '^(C|LANG|POSIX|en)' | egrep -i 'utf8|utf-8' | head -1) + if [ -z "$locale" ]; then + echo "WARNING: Not testing localization" + else + date=$(LC_ALL="$locale" date +"%a %d %b %Y at %H:%M:%S") + if ! LC_ALL="$locale" ./jq -nRe --arg date "$date" '$date|strptime("%a %d %b %Y at %H:%M:%S")? // false'; then + echo "jq does not honor LC_ALL environment variable" + exit 1; + fi + fi +fi + exit 0 |