ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "U.Nakamura" <usa@garbagecollect•jp>
To: ruby-dev@ruby-lang.org (ruby developers list)
Subject: [ruby-dev:46366] Re: [ruby-trunk - Bug #2154][Assigned] filesystem encoding of UNIX
Date: Fri, 2 Nov 2012 20:32:03 +0900	[thread overview]
Message-ID: <20121102113203.128936EA62@zanzibar.garbagecollect.jp> (raw)
In-Reply-To: <CANjopZE2=i90mitGWRffG3nkddT6df=yocXfpi3_011YM2Xj1w@mail.gmail.com>

こんにちは、なかむら(う)です。

In message "[ruby-dev:46310] Re: [ruby-trunk - Bug #2154][Assigned] filesystem encoding of UNIX"
    on Oct.29,2012 10:57:06, <akr@fsij•org> wrote:
> その時点の記憶はすでにないのですが、おそらく、
> locale と異なる encoding でパス名を扱いたい場合に、
> 設定できるようにするためではないかと思います。
> 
> とくに指定しなければ、default external は locale から設定されるので、
> 「UNIXにおけるfilesystem encodingはlocaleである」というのはそれほど
> 変ではないのではないでしょうか。

ふむ。
とすると、本当は、filesystem encodingを明示して設定するAPIが
合ったほうがいいんでしょうかね。
2.0.0にも間に合わなわなさそうなので今は深入りを避けますが。


さて、ここで問題なのですが、localeがUTF-8だとして、

  p File.expand_path("a").encoding                             # A
  Encoding.default_external = Encoding::EUC_JP
  p File.expand_path("a").encoding                             # B
  p File.expand_path("a".encode(Encoding::SHIFT_JIS)).encoding # C

としたとき、A, B, Cはそれぞれどうなるべきでしょう?

filesystem encoding(=default_external)を尊重するなら、

  A: UTF-8
  B: EUC-JP
  C: EUC-JP

になるはずで、1.9.3-p286は実際そうなります。
一方で、実は現在のtrunkは引数のencodingを尊重しており、

  A: US-ASCII (script encodingがそうなので)
  B: US-ASCII
  C: Shift_JIS

になります。

この辺色々悶々としていてるのですが、現時点での私の考えとして
は、

  * ファイルシステムのencodingが原則として固定であるプラット
    フォーム(つまり例えばWindows)では、内部変換を行い、引数の
    encodingで結果を返す。

  * ファイルシステムのencodingが個々の利用者にゆだねられてい
    て、システム的にはバイト列として扱われているプラットフォ
    ーム(つまり普通のUnix)では、内部では単にバイト列として扱
    い、default_externalにforce_encodingして結果を返す。

とするのがよいのかなあ、と思っています。
プラットフォームによって挙動が違うのがやや残念ですが、結局こ
れが既存のスクリプトに最も影響を与えない方法なのかなあ、と...

皆さんどう思われますか。


それでは。
-- 
U.Nakamura <usa@garbagecollect•jp>

  reply	other threads:[~2012-11-02 11:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-2154.20090928234343@ruby-lang.org>
2012-10-29  1:31 ` [ruby-dev:46309] [ruby-trunk - Bug #2154][Assigned] filesystem encoding of UNIX usa (Usaku NAKAMURA)
2012-10-29  1:57   ` [ruby-dev:46310] " Tanaka Akira
2012-11-02 11:32     ` U.Nakamura [this message]
2012-11-02 19:56       ` [ruby-dev:46375] " KOSAKI Motohiro
2012-11-02 20:17         ` [ruby-dev:46376] " Urabe Shyouhei
2012-11-03  0:00           ` [ruby-dev:46377] " KOSAKI Motohiro
2012-11-03 14:44             ` [ruby-dev:46386] " NARUSE, Yui
2012-11-05  6:13         ` [ruby-dev:46396] " U.Nakamura
2012-11-05  8:41           ` [ruby-dev:46398] " Hiroshi Shirosaki
2012-11-05  8:57             ` [ruby-dev:46399] " U.Nakamura
2012-11-05 12:33               ` [ruby-dev:46403] " Hiroshi Shirosaki
2012-11-05 12:53                 ` [ruby-dev:46405] " U.Nakamura
2012-11-05 16:55           ` [ruby-dev:46408] " KOSAKI Motohiro
2012-11-09 10:00 ` [ruby-dev:46463] [ruby-trunk - Bug #2154] " naruse (Yui NARUSE)
2017-10-22  1:40 ` [ruby-dev:50300] [Ruby trunk Bug#2154] " mame
2017-10-28 17:34 ` [ruby-dev:50308] [Ruby trunk Bug#2154][Rejected] " naruse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121102113203.128936EA62@zanzibar.garbagecollect.jp \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).