Be more careful about extracting encoding from locale strings on Windows.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 30 Mar 2020 15:14:58 +0000 (11:14 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 30 Mar 2020 15:14:58 +0000 (11:14 -0400)
commit6dac1e858b12c1fe67fcd72db4476210177e24c1
tree1fd851c14251a8740fe58faf587b23096417108c
parent4bdb3f3915ef45798a15405d2ee2080070c5b05d
Be more careful about extracting encoding from locale strings on Windows.

GetLocaleInfoEx() can fail on strings that setlocale() was perfectly
happy with.  A common way for that to happen is if the locale string
is actually a Unix-style string, say "et_EE.UTF-8".  In that case,
what's after the dot is an encoding name, not a Windows codepage number;
blindly treating it as a codepage number led to failure, with a fairly
silly error message.  Hence, check to see if what's after the dot is
all digits, and if not, treat it as a literal encoding name rather than
a codepage number.  This will do the right thing with many Unix-style
locale strings, and produce a more sensible error message otherwise.

Somewhat independently of that, treat a zero (CP_ACP) result from
GetLocaleInfoEx() as meaning that we must use UTF-8 encoding.

Back-patch to all supported branches.

Juan José Santamaría Flecha

Discussion: http://postgr.es/m/24905.1585445371@sss.pgh.pa.us
src/port/chklocale.c