From: Brian Candler Date: 2008-12-16T00:52:38+09:00 Subject: Re: ruby 1.9.1: Encoding trouble: broken US-ASCII String >> Wouldn't it be kinder to default to BINARY if the encoding is >> unspecified? > > The default encoding is pulled from your environment: LANG or > LC_CTYPE, I believe. This is very important and it makes simple > scripting fit in well with the environment. The code seems to say: - if an encoding is chosen in the environment but is unknown to Ruby, use ASCII-8BIT (aka BINARY) - if Ruby was built on a system where it doesn't know how to ask the environment for a language, then use US-ASCII So I would read from this that the OP has either fallen foul of the US-ASCII fallback (e.g. no langinfo.h when building under Cygwin), or else his environment has explicitly picked US-ASCII. There must have been a good reason why US-ASCII was chosen, rather than ASCII-8BIT, for systems without langinfo.h. Regards, Brian. rb_locale_encoding(void) { VALUE charmap = rb_locale_charmap(rb_cEncoding); int idx; if (NIL_P(charmap)) idx = rb_usascii_encindex(); else if ((idx = rb_enc_find_index(StringValueCStr(charmap))) < 0) idx = rb_ascii8bit_encindex(); if (rb_enc_registered("locale") < 0) enc_alias("locale", idx); return rb_enc_from_index(idx); } ... VALUE rb_locale_charmap(VALUE klass) { #if defined NO_LOCALE_CHARMAP return rb_usascii_str_new2("ASCII-8BIT"); #elif defined HAVE_LANGINFO_H char *codeset; codeset = nl_langinfo(CODESET); return rb_usascii_str_new2(codeset); #elif defined _WIN32 return rb_sprintf("CP%d", GetACP()); #else return Qnil; #endif } -- Posted via http://www.ruby-forum.com/.