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
2 changes: 1 addition & 1 deletion src/cjules/commands/patch.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module Cjules

if apply
if interactive
unless STDIN.tty? && STDOUT.tty?
unless STDIN.tty? && STDOUT.tty? && STDERR.tty?
STDERR.puts "error: --interactive requires a TTY"
return 2
end
Expand Down
13 changes: 6 additions & 7 deletions src/cjules/unidiff.cr
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ module Cjules
end

private def run_editor(editor : String, path : String, output : IO, display : IO) : Bool
# Allow editor commands with flags by going through the shell.
cmd = "#{editor} #{shell_escape(path)}"
status = Process.run("sh", ["-lc", cmd],
# Parse editor command into program + flags and pass path as a separate arg
# to avoid shell injection and quoting issues.
parts = editor.split
program = parts[0]
args = parts[1..] + [path]
status = Process.run(program, args,
input: input_for_editor,
output: display,
error: output)
Expand All @@ -222,10 +225,6 @@ module Cjules
STDIN
end

private def shell_escape(s : String) : String
"'" + s.gsub("'", %q('\'')).to_s + "'"
end

private def check_applies?(patch_path : String, output : IO) : Bool
out_io = IO::Memory.new
err = IO::Memory.new
Expand Down