ruby-changes:41924
From: nobu <ko1@a...>
Date: Fri, 4 Mar 2016 22:27:41 +0900 (JST)
Subject: [ruby-changes:41924] nobu:r53998 (trunk): ruby.c: warn_cr_in_shebang
nobu 2016-03-04 22:27:36 +0900 (Fri, 04 Mar 2016) New Revision: 53998 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53998 Log: ruby.c: warn_cr_in_shebang * ruby.c (load_file_internal): warn if shebang line ends with a carriage return. Modified files: trunk/ruby.c trunk/test/ruby/test_rubyoptions.rb Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 53997) +++ test/ruby/test_rubyoptions.rb (revision 53998) @@ -313,7 +313,7 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L313 [], /: no Ruby script found in input/) assert_in_out_err([{'RUBYOPT' => nil}], "#!ruby -KU -Eutf-8\r\np \"\u3042\"\r\n", - ["\"\u3042\""], [], + ["\"\u3042\""], /shebang line ends with \\r/, encoding: Encoding::UTF_8) bug4118 = '[ruby-dev:42680]' Index: ruby.c =================================================================== --- ruby.c (revision 53997) +++ ruby.c (revision 53998) @@ -1668,6 +1668,14 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1668 return (VALUE)iseq; } +static void +warn_cr_in_shebang(const char *str, long len) +{ + if (str[len-1] == '\n' && str[len-2] == '\r') { + rb_warn("shebang line ends with \\r may cause a problem"); + } +} + struct load_file_arg { VALUE parser; VALUE fname; @@ -1715,6 +1723,7 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1723 line_start++; RSTRING_GETMEM(line, str, len); if (len > 2 && str[0] == '#' && str[1] == '!') { + if (line_start == 1) warn_cr_in_shebang(str, len); if ((p = strstr(str+2, ruby_engine)) != 0) { goto start_read; } @@ -1732,6 +1741,7 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1741 return 0; RSTRING_GETMEM(line, str, len); + warn_cr_in_shebang(str, len); if ((p = strstr(str, ruby_engine)) == 0) { /* not ruby script, assume -x flag */ goto search_shebang; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/