Project

General

Profile

Actions

Bug #7043

closed

bug with Require

Added by eyeshield21 (Eyeshield 21) about 12 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p269 (2012-09-09 revision 36939) [x86_64-linux]
Backport:
[ruby-core:47629]

Description

~/projects/a/bins/bin.rb
~/projects/a/env.rb

cat ~/projects/a/bins/bin.rb
require File.join(File.dirname(FILE), %w{.. env})

cd ~/projects
ruby a/bins/bin.rb
/home/kostya/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- a/bins/../env (LoadError) from /home/kostya/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require'
from a/bins/bin.rb:1:in `'

cd ~/projects/a
ruby ./bins/bin.rb
OK

But, when i cd in and out, problem disappear (may be some path caching). When create new terminal problem is.
I also can replace code with expand_path, but in 1.8.7 there is no this problem.

Updated by eyeshield21 (Eyeshield 21) about 12 years ago

hm, i found a difference "./"

ruby ./a/bins/bin.rb
OK

ruby a/bins/bin.rb
/home/kostya/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- a/bins/../env (LoadError) from /home/kostya/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require'
from a/bins/bin.rb:1:in `'

Updated by mame (Yusuke Endoh) about 12 years ago

  • Status changed from Open to Rejected

This is an intentional change. Since 1.9, the default search path does
not include "." (current working directory) to make it more secure.

You may want to use require_relative which loads a file relative to the
directory that contains the loading file:

require_relative "../env"

--
Yusuke Endoh

Actions

Also available in: Atom PDF

Like0
Like0Like0