[Mac OS X] 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

···

--
« Le meilleur moyen de tenir sa parole est de ne jamais la donner. »
  (Napoléon Bonaparte)

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]

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.

···

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

=?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'

···

--
Posted via http://www.ruby-forum.com/\.

ok, fine thanks !

···

Brian Candler <b.candler@pobox.com> wrote:

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

If you want the long answer to that question, see
string19/string19.rb at master · candlerb/string19 · GitHub

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'

--
« C'est aujourd'hui que commence le reste de ta vie. »
   (Dale Carnegie)

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.

···

Ryan Davis <ryand-ruby@zenspider.com> wrote:

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.

--
« C'est aujourd'hui que commence le reste de ta vie. »
   (Dale Carnegie)