From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id CDC311F4B4 for ; Thu, 22 Oct 2020 15:05:37 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 81D37120B9F; Fri, 23 Oct 2020 00:04:58 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 36677120B9E for ; Fri, 23 Oct 2020 00:04:55 +0900 (JST) Received: by filterdrecv-p3iad2-786ff7f994-p4drr with SMTP id filterdrecv-p3iad2-786ff7f994-p4drr-19-5F919FBC-B4 2020-10-22 15:05:32.36312254 +0000 UTC m=+74222.639255401 Received: from herokuapp.com (unknown) by ismtpd0008p1iad2.sendgrid.net (SG) with ESMTP id DFVn1-W8TH-QXqTbSD2M8Q for ; Thu, 22 Oct 2020 15:05:32.261 +0000 (UTC) Date: Thu, 22 Oct 2020 15:05:32 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76376 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17254 X-Redmine-Issue-Author: znz X-Redmine-Sender: jeremyevans0 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BIWvWag7j7PcdXw4mWqWJgq9VitnBtOhcVg+CXx?= =?us-ascii?Q?hQdCYPrlxBZmBvvXHoxpExrFUzVIQxY5fzkK0nT?= =?us-ascii?Q?bThv7Tee+eUWaslCOFQEfjRrvDKIuFthKrEsfaz?= =?us-ascii?Q?yhUMIt1HashmKdoWEjqsPVKYbsIuY+PJ37L3oZ5?= =?us-ascii?Q?OO5wtjEdZhLUqLv9Q=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100506 Subject: [ruby-core:100506] [Ruby master Bug#17254] ENV.replace may set nil instead of the proper value X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17254 has been updated by jeremyevans0 (Jeremy Evans). znz (Kazuhiro NISHIYAMA) wrote in #note-2: > I dump duplicated keys with encoding. > Encodings of duplicated keys are same. Interesting. So it may be that duplicate keys in ENV in general are in issue? We generally think of ENV having unique keys, but I'm guessing that is not enforced by the kernel. Looking at the implementation of setenv(3)/unsetenv(3) on OpenBSD, it does specify that that there can be multiple environment entries with the same key, so Ruby's ENV implementation should probably not assume there is at most one entry per key. ---------------------------------------- Bug #17254: ENV.replace may set nil instead of the proper value https://bugs.ruby-lang.org/issues/17254#change-88128 * Author: znz (Kazuhiro NISHIYAMA) * Status: Open * Priority: Normal * ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- On docs.ruby-lang.org, it uses [snap ruby](https://snapcraft.io/ruby), and it failed to run `rdoc`. ``` Oct 07 13:20:08 docs-2020.ruby-lang.org env[6183]: rdoc --title Documentation for Ruby master --main README.md --output /var/www/docs.ruby-lang.org/releases/20200916140300/master -U --all --encoding=UTF-8 . Oct 07 13:20:08 docs-2020.ruby-lang.org env[6183]: :1:in `require': cannot load such file -- rubygems.rb (LoadError) Oct 07 13:20:08 docs-2020.ruby-lang.org env[6183]: from :1:in `' Oct 07 13:20:08 docs-2020.ruby-lang.org env[6183]: rake aborted! ``` I investigate it, it caused by setting nil instead of the proper value in `ENV.replace`. ``` vagrant@buster:/tmp/t$ cat Gemfile # frozen_string_literal: true source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } # gem "rails" vagrant@buster:/tmp/t$ env PATH=/var/www/docs.ruby-lang.org/shared/bundle/ruby/2.7.0/bin:/snap/bin:$PATH DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=1 bundle exec env -u RUBYOPT ruby -r/snap/ruby/189/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/setup -e 'p ENV["RUBYLIB"]' "/snap/ruby/189/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib" ``` Calling `ENV.clear` before `ENV.replace` resolves this issue. ``` vagrant@buster:/tmp/t$ cat /tmp/clear-before-replace.rb class << ENV alias orig_replace replace def replace(h) clear orig_replace(h) end end vagrant@buster:/tmp/t$ env PATH=/var/www/docs.ruby-lang.org/shared/bundle/ruby/2.7.0/bin:/snap/bin:$PATH DEBIAN_DISABLE_RUBYGEMS_INTEGRATION=1 bundle exec env -u RUBYOPT ruby -r/tmp/clear-before-replace -r/snap/ruby/189/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/setup -e 'p ENV["RUBYLIB"]' "/snap/ruby/189/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib:/snap/ruby/189/lib/ruby/2.7.0:/snap/ruby/189/lib/ruby/2.7.0/amd64" ``` Where should call `ENV.clear`? In `ENV.replace` or caller of `ENV.replace`? ---Files-------------------------------- full-env-log.txt (8.96 KB) rdoc-failed-log.txt (2.57 KB) -- https://bugs.ruby-lang.org/