From where is coming __CF_USER_TEXT_ENCODING?

from a ruby script if i list the ENV hash i get (between others) :

__CF_USER_TEXT_ENCODING => 0x1F5:0:1

when the script is ran from a user and :

__CF_USER_TEXT_ENCODING => 0x0:0:1

when run via sudo.

however i have :
imyt% sudo cat /var/root/.CFUserTextEncoding
0:1%

imyt% cat ~/.CFUserTextEncoding
0:1%

pretty the same.

could that explain the fact that when running a script via sudo i do
have to force encoding ie :
File.open(MACSOUP_SIGNATURES_FILE,:encoding => “UTF-8”)

and no need for ":encoding => “UTF-8"” when running as user.

i’m suing :
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10]

and notice that in both cases i do have :
LANG => fr_FR.UTF-8

On Oct 20, 2010, at 11:10 , Une B. wrote:

have to force encoding ie :
File.open(MACSOUP_SIGNATURES_FILE,:encoding => “UTF-8”)

and no need for ":encoding => “UTF-8"” when running as user.

i’m suing :
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10]

please don’t sue ruby :stuck_out_tongue:

and notice that in both cases i do have :
LANG => fr_FR.UTF-8

501 % env | grep CF
__CF_USER_TEXT_ENCODING=0x1F8:0:0
502 % ls -l ~/.CF*
ls: /Users/ryan/.CF*: No such file or directory

I’m set for English env in System Prefs on OSX so I was a bit surprised
to see the env var.

“CF” is a prefix that stands for “Core Foundation”, aka the bottom layer
of cocoa… so you may want to fire up xcode’s lovely help system and
search around there.

=?ISO-8859-1?Q?Une_B=E9vue?= wrote in post #955862:

could that explain the fact that when running a script via sudo i do
have to force encoding ie :
File.open(MACSOUP_SIGNATURES_FILE,:encoding => “UTF-8”)

and no need for ":encoding => “UTF-8"” when running as user.

If you want the long answer to that question, see

The short answer is: (1) Ruby’s behaviour when dealing with strings read
from files is influenced by the contents of environment variables,
unless you explicitly tell it otherwise; and (2) sudo clears out
environment variables, unless you explicitly tell it otherwise.

and notice that in both cases i do have :
LANG => fr_FR.UTF-8

The rules for locale setting are complex, and there are other
environment variables such as LC_ALL which take precedence over it. See
‘man setlocale’

Ryan D. [email protected] wrote:

of cocoa… so you may want to fire up xcode’s lovely help system and
search around there.

yes ok right, __CF_USER_TEXT_ENCODING is coming from CFUserTextEncoding.

i got :
imyt% env | grep CF
__CF_USER_TEXT_ENCODING=0x1F5:0:1
imyt% sudo env | grep CF
__CF_USER_TEXT_ENCODING=0x0:0:1
imyt%

1F5 and 0 are, respectively the UID of mine and root.

Brian C. [email protected] wrote:

and notice that in both cases i do have :
LANG => fr_FR.UTF-8

The rules for locale setting are complex, and there are other
environment variables such as LC_ALL which take precedence over it. See
‘man setlocale’

ok, fine thanks !