Forum: Ruby-core require_relative fails in an eval'ed file

Posted by Eregon (Benoit Daloze) (Guest)
on 2012-07-06 13:07
(Received via mailing list)
Issue #4487 has been updated by Eregon (Benoit Daloze).


naruse (Yui NARUSE) wrote:
> Eregon (Benoit Daloze) wrote:
> > From the process current working directory I guess, especially since you 
almost always launch IRB from a terminal.
>
> require_relative is introduced to avoid accidentally require a malicious file on 
the current working directory.
> So it can't be acceptable.
> Use require or load on such case.

I see, you're right.
Indeed, with this in mind I think it's not worth changing, and the 
actual require_relative behavior is clearer (relative to "this file" 
directory, if there is no accurate "this file", just #raise).
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27861

Author: rogerdpack (Roger Pack)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version:
ruby -v: -


=begin
Hello all.

 $cat eval_me1.rb
 eval(File.read('eval_me2.rb'), binding, 
File.expand_path('./eval_me2.rb'))
 $cat eval_me2.rb
 require_relative 'eval_me1.rb'
 $ ruby eval_me1.rb
 C:/dev/ruby/faster_require/spec/eval_me2.rb:1:in `require_relative': 
cannot infer basepath (LoadError)
        from C:/dev/ruby/faster_require/spec/eval_me2.rb:1:in `<main>'
        from eval_me1.rb:1:in `eval'
        from eval_me1.rb:1:in `<main>'

I suppose was assuming that if eval included a filename, then 
require_relative would work from within it. Perhaps I am mistaken?
Thanks!
-r
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.