1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (load_file_internal): assumes -x flag if no "ruby" is in

the shebang line.  [ruby-dev:39015]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-08-05 10:19:18 +00:00
parent cb9038cbaf
commit 8bc6c71547
3 changed files with 20 additions and 31 deletions

View file

@ -1,3 +1,8 @@
Wed Aug 5 19:19:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (load_file_internal): assumes -x flag if no "ruby" is in
the shebang line. [ruby-dev:39015]
Wed Aug 5 19:11:01 2009 NARUSE, Yui <naruse@ruby-lang.org>
* ruby.c (rb_stdio_set_default_encoding): declared.

34
ruby.c
View file

@ -1508,6 +1508,7 @@ load_file_internal(VALUE arg)
rb_funcall(f, set_encoding, 1, rb_enc_from_encoding(enc));
if (opt->xflag) {
search_shebang:
forbid_setid("-x");
opt->xflag = Qfalse;
while (!NIL_P(line = rb_io_gets(f))) {
@ -1532,37 +1533,8 @@ load_file_internal(VALUE arg)
return 0;
if ((p = strstr(RSTRING_PTR(line), "ruby")) == 0) {
void rb_thread_stop_timer_thread(void);
/* not ruby script, kick the program */
char **argv;
char *path;
char *pend = RSTRING_PTR(line) + RSTRING_LEN(line);
p = RSTRING_PTR(line); /* skip `#!' */
if (pend[-1] == '\n')
pend--; /* chomp line */
if (pend[-1] == '\r')
pend--;
*pend = '\0';
while (p < pend && ISSPACE(*p))
p++;
path = p; /* interpreter path */
while (p < pend && !ISSPACE(*p))
p++;
*p++ = '\0';
if (p < pend) {
argv = ALLOCA_N(char *, origarg.argc + 3);
argv[1] = p;
MEMCPY(argv + 2, origarg.argv + 1, char *, origarg.argc);
}
else {
argv = origarg.argv;
}
argv[0] = path;
rb_thread_stop_timer_thread();
execv(path, argv);
rb_fatal("Can't exec %s", path);
/* not ruby script, assume -x flag */
goto search_shebang;
}
start_read:

View file

@ -45,6 +45,18 @@ class TestSystem < Test::Unit::TestCase
assert_equal('', `#{ruby} -x #{tmpfilename}`)
assert_equal('555', `#{ruby} -x #{tmpfilename} -zzz=555`)
tmp = open(tmpfilename, "w")
tmp.print "#! /non/exist\\interpreter?/./to|be:ignored\n";
tmp.print "this is a leading junk\n";
tmp.print "#! /usr/local/bin/ruby -s\n";
tmp.print "print $zzz\n";
tmp.print "__END__\n";
tmp.print "this is a trailing junk\n";
tmp.close
assert_equal('', `#{ruby} #{tmpfilename}`)
assert_equal('555', `#{ruby} #{tmpfilename} -zzz=555`)
tmp = open(tmpfilename, "w")
for i in 1..5
tmp.print i, "\n"