ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: zn@mbf.nifty.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:102006] [Ruby master Bug#17517] File.expand_path returns us-ascii when both arguments are ascii compat
Date: Tue, 12 Jan 2021 00:50:32 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-89851.20210112005031.14@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17517.20210106113249.14@ruby-lang.org

Issue #17517 has been updated by znz (Kazuhiro NISHIYAMA).


Original problem is `__FILE__` and `__dir__` are us-ascii only when loaded by `relative_require`.

```
% cat hoge.rb
p __FILE__.encoding
p __dir__.encoding
% cat require_relative.rb
require_relative 'hoge'
% ruby require_relative.rb
#<Encoding:US-ASCII>
#<Encoding:US-ASCII>
% cat require.rb
require './hoge'
% ruby require.rb
#<Encoding:UTF-8>
#<Encoding:UTF-8>
```

----------------------------------------
Bug #17517: File.expand_path returns us-ascii when both arguments are ascii compat
https://bugs.ruby-lang.org/issues/17517#change-89851

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Is this intentional?

```ruby
p __dir__.encoding  #=> #<Encoding:UTF-8>
p 'hoge'.encoding   #=> #<Encoding:UTF-8>
p File.expand_path('hoge', __dir__).encoding #=> #<Encoding:US-ASCII>
```

```
% docker run -it --rm ghcr.io/ruby/all-ruby env ALL_RUBY_SINCE=ruby-1.9 ./all-ruby -e 'p File.expand_path("hoge".encode("utf-8"), "/".encode("utf-8")).encoding'
ruby-1.9.0-0        -e:1:in `encode': transcoding not supported (from ASCII-8BIT to UTF-8) (ArgumentError)
                    	from -e:1:in `<main>'
                exit 1
ruby-1.9.0-1        #<Encoding:ASCII-8BIT>
ruby-1.9.0-2        #<Encoding:US-ASCII>
...
ruby-1.9.1-p129     #<Encoding:US-ASCII>
ruby-1.9.1-p243     #<Encoding:UTF-8>
...
ruby-1.9.2-preview1 #<Encoding:UTF-8>
ruby-1.9.2-preview3 #<Encoding:US-ASCII>
...
ruby-3.0.0          #<Encoding:US-ASCII>
```



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2021-01-12  0:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 11:32 [ruby-core:101954] [Ruby master Bug#17517] File.expand_path returns us-aascii when both arguments are ascii compat zn
2021-01-06 12:49 ` [ruby-core:101957] " jean.boussier
2021-01-07  4:39 ` [ruby-core:101969] [Ruby master Bug#17517] File.expand_path returns us-ascii " duerst
2021-01-12  0:50 ` zn [this message]
2021-01-13 15:19 ` [ruby-core:102062] " nobu

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=redmine.journal-89851.20210112005031.14@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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).