[ruby-core:35474] Fwd: You rogerpack2005@gmail.com are not member (ruby-core ML)

20 views
Skip to first unread message

Roger Pack

unread,
Mar 9, 2011, 6:29:07 PM3/9/11
to ruby...@ruby-lang.org
As a note, when I update redmine, I get these to my (other) email
account, in case it's not expected.
Cheers!
-r


---------- Forwarded message ----------
From: Roger Pack <rogerp...@gmail.com>
Date: Wed, Mar 9, 2011 at 4:12 PM
Subject: Fwd: You rogerp...@gmail.com are not member (ruby-core ML)
To: roger...@gmail.com


---------- Forwarded message ----------
From:  <ruby-co...@ruby-lang.org>
Date: Wed, Mar 9, 2011 at 11:25 AM
Subject: You rogerp...@gmail.com are not member (ruby-core ML)
To: rogerp...@gmail.com


You are not a member of this mailing list <ruby...@ruby-lang.org>.

If you want to know the general guide of this list, please send an email
with the body (case-insensitive):

       # guide

to the address

       ruby-c...@ruby-lang.org

Note that the mail should not be encoded in base64.

Roger Pack

unread,
Apr 1, 2011, 12:55:52 PM4/1/11
to ruby...@ruby-lang.org
Could anybody look at this [emails are being sent by the logged in
user, not subscribed]? Currently my updates to redmine tickets don't
get copied to ruby-core because of it, I believe...
Thanks much.
-r

Yui NARUSE

unread,
Jun 26, 2011, 5:27:44 AM6/26/11
to ruby...@ruby-lang.org

Issue #4487 has been updated by Yui NARUSE.

Status changed from Open to Assigned
Assignee set to Yusuke Endoh


----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
http://redmine.ruby-lang.org/issues/4487

Author: Roger Pack
Status: Assigned
Priority: Normal
Assignee: Yusuke Endoh
Category:
Target version:
ruby -v: ruby 1.9.3dev (2011-03-04 trunk 31024) [i386-mingw32]


=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

--
http://redmine.ruby-lang.org

Yusuke ENDOH

unread,
Jul 4, 2011, 1:32:17 PM7/4/11
to ruby...@ruby-lang.org
Hello,

>  $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?


I think your expectation is reasonable, though I personally dislike
the eval's feature to fake filepath.


The following patch makes require_relative use the given file path.
I'm afraid if I should include this patch in 1.9.3 because I can't
estimate the impact of this patch. What do you think?


diff --git a/vm_eval.c b/vm_eval.c
index 7df7f5f..3710401 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1007,7 +1007,7 @@ eval_string_with_cref(VALUE self, VALUE src,
VALUE scope, NODE *cref, const char
/* make eval iseq */
th->parse_in_eval++;
th->mild_compile_error++;
- iseqval = rb_iseq_compile(src, rb_str_new2(file), INT2FIX(line));
+ iseqval = rb_iseq_compile_with_option(src, rb_str_new2(file),
rb_str_new2(file), INT2FIX(line), Qnil);
th->mild_compile_error--;
th->parse_in_eval--;

--
Yusuke Endoh <ma...@tsg.ne.jp>

Yusuke Endoh

unread,
Jul 4, 2011, 11:52:50 PM7/4/11
to ruby...@ruby-lang.org

Issue #4487 has been updated by Yusuke Endoh.

Assignee changed from Yusuke Endoh to Yukihiro Matsumoto

Related to #4352.

I need matz's judgment.

--
Yusuke Endoh <ma...@tsg.ne.jp>


----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
http://redmine.ruby-lang.org/issues/4487

Author: Roger Pack
Status: Assigned
Priority: Normal

Assignee: 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?

LTe (Piotr Niełacny)

unread,
Jul 5, 2012, 4:07:56 AM7/5/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by LTe (Piotr Niełacny).


=begin
If in irb we can execute

(({load("file.rb")}))

why we can't

(({require_relative("file")}))

Ruby just return exception (LoadError: cannot infer basepath). Unfortunately, this is a 'lie' because ruby can recognize basepath.
=end
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27825

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



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

shyouhei (Shyouhei Urabe)

unread,
Jul 5, 2012, 4:26:24 AM7/5/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by shyouhei (Shyouhei Urabe).


=begin

@LTe sorry, I can't get it. load loads from $LOAD_PATH, while require_relative requires from relative path. They are different.

=end

----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27826

LTe (Piotr Niełacny)

unread,
Jul 6, 2012, 3:04:25 AM7/6/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by LTe (Piotr Niełacny).


@shyouhei yes I agree but load method tries to load file from relative path. When load method can't find file in relative path it loads from $LOAD_PATH. The same can be done by require_relative (recognize path).

https://github.com/ruby/ruby/pull/139
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27849

shyouhei (Shyouhei Urabe)

unread,
Jul 6, 2012, 4:52:40 AM7/6/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by shyouhei (Shyouhei Urabe).


=begin
@LTe I'd rather ask you "require_relative loads something relative from WHAT?"

Obviously it is not relative from your mind :)

Current require_relative loads relative from where the require_relative command is written. So when in IRB sessions, it fails to infer where it is beacuse the command is written in a non-file (console).

OTOH load loads from process PWD, which is possible in IRB.

So the point is, if you want require_relative to work on an IRB session, you have to define "from where require_relative should search relativeness".
=end

----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27854

Eregon (Benoit Daloze)

unread,
Jul 6, 2012, 5:13:08 AM7/6/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by Eregon (Benoit Daloze).


shyouhei (Shyouhei Urabe) wrote:
> Current require_relative loads relative from where the require_relative command is written. So when in IRB sessions, it fails to infer where it is beacuse the command is written in a non-file (console).
>
> OTOH load loads from process PWD, which is possible in IRB.
>
> So the point is, if you want require_relative to work on an IRB session, you have to define "from where require_relative should search relativeness".

From the process current working directory I guess, especially since you almost always launch IRB from a terminal.

Personally I'm doing `require './myfile'` which is not the most elegant, but if you don't have completion in IRB, that's shorter to type.

Otherwise, there's always the option to do `irb -I.` and use plain `require`.
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27856

naruse (Yui NARUSE)

unread,
Jul 6, 2012, 5:59:29 AM7/6/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by naruse (Yui NARUSE).


Eregon (Benoit Daloze) wrote:
> shyouhei (Shyouhei Urabe) wrote:
> > Current require_relative loads relative from where the require_relative command is written. So when in IRB sessions, it fails to infer where it is beacuse the command is written in a non-file (console).
> >
> > OTOH load loads from process PWD, which is possible in IRB.
> >
> > So the point is, if you want require_relative to work on an IRB session, you have to define "from where require_relative should search relativeness".
>
> From the process current working directory I guess, especially since you almost always launch IRB from a terminal.
>
> Personally I'm doing `require './myfile'` which is not the most elegant, but if you don't have completion in IRB, that's shorter to type.
>
> Otherwise, there's always the option to do `irb -I.` and use plain `require`.

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.
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27858

shyouhei (Shyouhei Urabe)

unread,
Jul 6, 2012, 6:08:03 AM7/6/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by shyouhei (Shyouhei Urabe).


naruse (Yui NARUSE) wrote:
> 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'm not pretty sure about this. Is there a chance for a (proposed behaviour of) require_relative to require a malicious file on the current directory?

Because you are on an IRB session and intentionally emitting require_relative (not require), I doubt the danger you say.

----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27859

naruse (Yui NARUSE)

unread,
Jul 6, 2012, 6:21:04 AM7/6/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by naruse (Yui NARUSE).


shyouhei (Shyouhei Urabe) wrote:
> naruse (Yui NARUSE) wrote:
> > 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'm not pretty sure about this. Is there a chance for a (proposed behaviour of) require_relative to require a malicious file on the current directory?
>
> Because you are on an IRB session and intentionally emitting require_relative (not require), I doubt the danger you say.

* irb is not the only user of eval.
* A user won't always use require_relative intentionally.
* There is a suitable another way: require './myfile'

With those reason, I don't think require_relative should be changed.
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-27860

Eregon (Benoit Daloze)

unread,
Jul 6, 2012, 7:06:20 AM7/6/12
to ruby...@ruby-lang.org

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

ko1 (Koichi Sasada)

unread,
Jul 14, 2012, 2:00:12 AM7/14/12
to ruby...@ruby-lang.org

Issue #4487 has been updated by ko1 (Koichi Sasada).

Assignee changed from matz (Yukihiro Matsumoto) to mame (Yusuke Endoh)

mame-san, please ask matz.
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-28035

Author: rogerdpack (Roger Pack)
Status: Assigned
Priority: Normal
Assignee: mame (Yusuke Endoh)

mame (Yusuke Endoh)

unread,
Feb 1, 2013, 11:06:59 PM2/1/13
to ruby...@ruby-lang.org

Issue #4487 has been updated by mame (Yusuke Endoh).

Subject changed from require_relative fails in an eval'ed file to require_relative fails in an eval&#x27;ed file
Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto)
Target version set to next minor


----------------------------------------
Bug #4487: require_relative fails in an eval&#x27;ed file
https://bugs.ruby-lang.org/issues/4487#change-35777

Author: rogerdpack (Roger Pack)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor

Conrad.Irwin (Conrad Irwin)

unread,
Mar 23, 2013, 1:50:17 AM3/23/13
to ruby...@ruby-lang.org

Issue #4487 has been updated by Conrad.Irwin (Conrad Irwin).


This bug also affects pry: https://github.com/pry/pry/issues/880. Our use-case is slightly different because we are doing TOPLEVEL_BINDING.eval("some code", "/absolute/path.rb").

I think that when an absolute path is set in eval, then require_relative should use it.
----------------------------------------
Bug #4487: require_relative fails in an eval'ed file
https://bugs.ruby-lang.org/issues/4487#change-37839
Reply all
Reply to author
Forward
0 new messages