[Mac OS X] from where is coming __CF_USER_TEXT_ENCODING ?

U

Une Bévue

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
 
R

Ryan Davis

=20
from a ruby script if i list the ENV hash i get (between others) :
=20
__CF_USER_TEXT_ENCODING =3D> 0x1F5:0:1
=20
when the script is ran from a user and :
=20
__CF_USER_TEXT_ENCODING =3D> 0x0:0:1
=20
when run via sudo.
=20
however i have :
imyt% sudo cat /var/root/.CFUserTextEncoding
0:1%
=20
imyt% cat ~/.CFUserTextEncoding
0:1%
=20
pretty the same.
=20
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 =3D> "UTF-8")
=20
and no need for ":encoding =3D> "UTF-8"" when running as user.
=20
i'm suing :
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10]

please don't sue ruby :p
and notice that in both cases i do have :
LANG =3D> fr_FR.UTF-8

501 % env | grep CF
__CF_USER_TEXT_ENCODING=3D0x1F8: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.
 
B

Brian Candler

=?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
http://github.com/candlerb/string19/blob/master/string19.rb

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'
 
U

Une Bévue

Brian Candler said:
If you want the long answer to that question, see
http://github.com/candlerb/string19/blob/master/string19.rb

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.


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 !
 
U

Une Bévue

Ryan Davis said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top