diff --git a/CHANGELOG.md b/CHANGELOG.md index 4138eee17825..914306eb8003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Bug fixes: Compatibility: * Fix `Module#include` so a module included into a reopened nested module is added into an ancestors chain (#3570, @andrykonchin). +* Fix `Kernel#eval` to ignore shebang with non-Ruby interpreter (#3623, @andrykonchin). Performance: diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb index 454bc4a58e5c..5f4cd27da024 100644 --- a/spec/ruby/core/kernel/eval_spec.rb +++ b/spec/ruby/core/kernel/eval_spec.rb @@ -274,6 +274,26 @@ class EvalSpecs eval("").should == nil end + context "with shebang" do + it "ignores shebang with ruby interpreter" do + pid = eval(<<~CODE.b) + #!/usr/bin/env ruby + Process.pid + CODE + + pid.should == Process.pid + end + + it "ignores shebang with non-ruby interpreter" do + pid = eval(<<~CODE.b) + #!/usr/bin/env puma + Process.pid + CODE + + pid.should == Process.pid + end + end + # See language/magic_comment_spec.rb for more magic comments specs describe "with a magic encoding comment" do it "uses the magic comment encoding for the encoding of literal strings" do diff --git a/src/main/c/yarp/src/prism.c b/src/main/c/yarp/src/prism.c index c546c62aa0c3..928b682eb35d 100644 --- a/src/main/c/yarp/src/prism.c +++ b/src/main/c/yarp/src/prism.c @@ -21467,7 +21467,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm pm_parser_warn_shebang_carriage_return(parser, parser->start, length); if (newline != NULL) parser->encoding_comment_start = newline + 1; search_shebang = false; - } else { + } else if (!parser->parsing_eval) { // See https://github.com/ruby/prism/pull/2952 search_shebang = true; } }