Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion io.c
Original file line number Diff line number Diff line change
Expand Up @@ -8079,7 +8079,12 @@ ruby_popen_writer(char *const *argv, rb_pid_t *pid)
int write_pair[2];
# endif

int result = rb_cloexec_pipe(write_pair);
#ifdef HAVE_PIPE2
int result = pipe2(write_pair, O_CLOEXEC);
#else
int result = pipe(write_pair);
#endif

*pid = -1;
if (result == 0) {
# ifdef HAVE_WORKING_FORK
Expand Down
23 changes: 21 additions & 2 deletions prism/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -14232,6 +14232,25 @@ parse_assocs(pm_parser_t *parser, pm_static_literals_t *literals, pm_node_t *nod
return contains_keyword_splat;
}

static inline bool
argument_allowed_for_bare_hash(pm_parser_t *parser, pm_node_t *argument) {
if (pm_symbol_node_label_p(argument)) {
return true;
}

switch (PM_NODE_TYPE(argument)) {
case PM_CALL_NODE: {
pm_call_node_t *cast = (pm_call_node_t *) argument;
if (cast->opening_loc.start == NULL && cast->arguments != NULL) {
return false;
}
break;
}
default: break;
}
return accept1(parser, PM_TOKEN_EQUAL_GREATER);
}

/**
* Append an argument to a list of arguments.
*/
Expand Down Expand Up @@ -14389,7 +14408,7 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
bool contains_keywords = false;
bool contains_keyword_splat = false;

if (pm_symbol_node_label_p(argument) || accept1(parser, PM_TOKEN_EQUAL_GREATER)) {
if (argument_allowed_for_bare_hash(parser, argument)){
if (parsed_bare_hash) {
pm_parser_err_previous(parser, PM_ERR_ARGUMENT_BARE_HASH);
}
Expand Down Expand Up @@ -22620,7 +22639,7 @@ static const char *
pm_strnstr(const char *big, const char *little, size_t big_length) {
size_t little_length = strlen(little);

for (const char *big_end = big + big_length; big < big_end; big++) {
for (const char *max = big + big_length - little_length; big <= max; big++) {
if (*big == *little && memcmp(big, little, little_length) == 0) return big;
}

Expand Down
41 changes: 41 additions & 0 deletions test/prism/errors/command_calls_35.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
p(p a, x: b => value)
^~ unexpected '=>'; expected a `)` to close the arguments
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

p(p a, x: => value)
^~ unexpected '=>'; expected a `)` to close the arguments
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

p(p a, &block => value)
^~ unexpected '=>'; expected a `)` to close the arguments
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

p(p a, *args => value)
^~ unexpected '=>'; expected a `)` to close the arguments
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

p(p a, **kwargs => value)
^~ unexpected '=>'; expected a `)` to close the arguments
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

p p 1, &block => 2, &block
^~ unexpected '=>', expecting end-of-input
^~ unexpected '=>', ignoring it
^ unexpected ',', expecting end-of-input
^ unexpected ',', ignoring it
^ unexpected '&', ignoring it

p p p 1 => 2 => 3 => 4
^~ unexpected '=>', expecting end-of-input
^~ unexpected '=>', ignoring it

p[p a, x: b => value]
^ expected a matching `]`
^ unexpected ']', expecting end-of-input
^ unexpected ']', ignoring it

6 changes: 6 additions & 0 deletions test/prism/fixtures/command_method_call.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ def foo = bar 1
!foo 1 or !bar 2

not !foo 1

foo(bar baz, key => value)

foo(bar baz, KEY => value)

foo(bar baz, :key => value)
21 changes: 21 additions & 0 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,27 @@ def test_crash_report_pipe
end
end

def test_crash_report_pipe_script
omit "only runs on Linux" unless RUBY_PLATFORM.include?("linux")

Tempfile.create(["script", ".sh"]) do |script|
Tempfile.create("crash_report") do |crash_report|
script.write(<<~BASH)
#!/usr/bin/env bash

cat > #{crash_report.path}
BASH
script.close

FileUtils.chmod("+x", script)

assert_crash_report("| #{script.path}") do
assert_include(File.read(crash_report.path), "[BUG] Segmentation fault at")
end
end
end
end

def test_DATA
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
t.puts "puts DATA.read.inspect"
Expand Down