aboutsummaryrefslogtreecommitdiffstats
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-04 13:27:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-04 13:27:36 +0000
commit142233ea2921afb3e76c590c9a747e968efbee7d (patch)
tree71be86a0a626a331d7e3138f852a01f354b48e4f /ruby.c
parentdd857a7ba49b81c3c319e5c299d0da54b1b760d6 (diff)
downloadruby-142233ea2921afb3e76c590c9a747e968efbee7d.tar.gz
ruby.c: warn_cr_in_shebang
* ruby.c (load_file_internal): warn if shebang line ends with a carriage return. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/ruby.c b/ruby.c
index 3ec75b9dc6..e77a862258 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1668,6 +1668,14 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
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)
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)
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;