[ruby/prism] Do not warn \r in shebang on windows
https://github.com/ruby/prism/commit/e8c862ca1f
This commit is contained in:
parent
a542479a75
commit
15135030e5
@ -21772,6 +21772,9 @@ pm_strnstr(const char *big, const char *little, size_t big_length) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define pm_parser_warn_shebang_carriage_return(parser, start, length) ((void) 0)
|
||||||
|
#else
|
||||||
/**
|
/**
|
||||||
* Potentially warn the user if the shebang that has been found to include
|
* Potentially warn the user if the shebang that has been found to include
|
||||||
* "ruby" has a carriage return at the end, as that can cause problems on some
|
* "ruby" has a carriage return at the end, as that can cause problems on some
|
||||||
@ -21783,6 +21786,7 @@ pm_parser_warn_shebang_carriage_return(pm_parser_t *parser, const uint8_t *start
|
|||||||
pm_parser_warn(parser, start, start + length, PM_WARN_SHEBANG_CARRIAGE_RETURN);
|
pm_parser_warn(parser, start, start + length, PM_WARN_SHEBANG_CARRIAGE_RETURN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the shebang when initializing the parser. This function assumes that
|
* Process the shebang when initializing the parser. This function assumes that
|
||||||
@ -21973,9 +21977,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
|
|||||||
const char *engine;
|
const char *engine;
|
||||||
if ((engine = pm_strnstr((const char *) parser->start, "ruby", length)) != NULL) {
|
if ((engine = pm_strnstr((const char *) parser->start, "ruby", length)) != NULL) {
|
||||||
if (newline != NULL) {
|
if (newline != NULL) {
|
||||||
size_t length_including_newline = length + 1;
|
pm_parser_warn_shebang_carriage_return(parser, parser->start, length + 1);
|
||||||
pm_parser_warn_shebang_carriage_return(parser, parser->start, length_including_newline);
|
|
||||||
|
|
||||||
parser->encoding_comment_start = newline + 1;
|
parser->encoding_comment_start = newline + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22015,10 +22017,9 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
|
|||||||
const char *engine;
|
const char *engine;
|
||||||
if ((engine = pm_strnstr((const char *) cursor, "ruby", length)) != NULL) {
|
if ((engine = pm_strnstr((const char *) cursor, "ruby", length)) != NULL) {
|
||||||
found_shebang = true;
|
found_shebang = true;
|
||||||
if (newline != NULL) {
|
|
||||||
size_t length_including_newline = length + 1;
|
|
||||||
pm_parser_warn_shebang_carriage_return(parser, cursor, length_including_newline);
|
|
||||||
|
|
||||||
|
if (newline != NULL) {
|
||||||
|
pm_parser_warn_shebang_carriage_return(parser, cursor, length + 1);
|
||||||
parser->encoding_comment_start = newline + 1;
|
parser->encoding_comment_start = newline + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,42 +321,48 @@ module Prism
|
|||||||
assert_warning("tap { redo; foo }", "statement not reached")
|
assert_warning("tap { redo; foo }", "statement not reached")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_shebang_ending_with_carriage_return
|
if RbConfig::CONFIG["host_os"].match?(/bccwin|cygwin|djgpp|mingw|mswin|wince/i)
|
||||||
msg = "shebang line ending with \\r may cause problems"
|
def test_shebang_ending_with_carriage_return
|
||||||
|
refute_warning("#!ruby\r\np(123)\n", compare: false)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def test_shebang_ending_with_carriage_return
|
||||||
|
msg = "shebang line ending with \\r may cause problems"
|
||||||
|
|
||||||
assert_warning(<<~RUBY, msg, compare: false)
|
assert_warning(<<~RUBY, msg, compare: false)
|
||||||
#!ruby\r
|
#!ruby\r
|
||||||
p(123)
|
p(123)
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
assert_warning(<<~RUBY, msg, compare: false)
|
assert_warning(<<~RUBY, msg, compare: false)
|
||||||
#!ruby \r
|
#!ruby \r
|
||||||
p(123)
|
p(123)
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
assert_warning(<<~RUBY, msg, compare: false)
|
assert_warning(<<~RUBY, msg, compare: false)
|
||||||
#!ruby -Eutf-8\r
|
#!ruby -Eutf-8\r
|
||||||
p(123)
|
p(123)
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
# Used with the `-x` object, to ignore the script up until the first shebang that mentioned "ruby".
|
# Used with the `-x` object, to ignore the script up until the first shebang that mentioned "ruby".
|
||||||
assert_warning(<<~SCRIPT, msg, compare: false)
|
assert_warning(<<~SCRIPT, msg, compare: false)
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Some initial shell script or other content
|
# Some initial shell script or other content
|
||||||
# that Ruby should ignore
|
# that Ruby should ignore
|
||||||
echo "This is shell script part"
|
echo "This is shell script part"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
#! /usr/bin/env ruby -Eutf-8\r
|
#! /usr/bin/env ruby -Eutf-8\r
|
||||||
# Ruby script starts here
|
# Ruby script starts here
|
||||||
puts "Hello from Ruby!"
|
puts "Hello from Ruby!"
|
||||||
SCRIPT
|
SCRIPT
|
||||||
|
|
||||||
refute_warning("#ruby not_a_shebang\r\n", compare: false)
|
refute_warning("#ruby not_a_shebang\r\n", compare: false)
|
||||||
|
|
||||||
# CRuby doesn't emit the warning if a malformed file only has `\r` and not `\n`.
|
# CRuby doesn't emit the warning if a malformed file only has `\r` and not `\n`.
|
||||||
# https://bugs.ruby-lang.org/issues/20700
|
# https://bugs.ruby-lang.org/issues/20700
|
||||||
refute_warning("#!ruby\r", compare: false)
|
refute_warning("#!ruby\r", compare: false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_warnings_verbosity
|
def test_warnings_verbosity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user