Skip to content

Commit

Permalink
Merge pull request rails#45708 from jonathanhefner/encrypted-config-t…
Browse files Browse the repository at this point in the history
…mp-path-with-spaces

Support spaces in file path when invoking editor
  • Loading branch information
jonathanhefner authored Jul 31, 2022
2 parents 0098f55 + 75d4e87 commit 6b042ad
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
5 changes: 5 additions & 0 deletions railties/lib/rails/command/helpers/editor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "shellwords"
require "active_support/encrypted_file"

module Rails
Expand All @@ -22,6 +23,10 @@ def ensure_editor_available(command:)
end
end

def system_editor(file_path)
system(*Shellwords.split(ENV["EDITOR"]), file_path.to_s)
end

def catch_editing_exceptions
yield
rescue Interrupt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "pathname"
require "shellwords"
require "active_support"
require "rails/command/helpers/editor"
require "rails/command/environment_argument"
Expand Down Expand Up @@ -93,10 +92,7 @@ def ensure_credentials_have_been_added

def change_credentials_in_system_editor
catch_editing_exceptions do
credentials.change do |tmp_path|
system(*Shellwords.split(ENV["EDITOR"]), tmp_path.to_s)
end

credentials.change { |tmp_path| system_editor(tmp_path) }
say "File encrypted and saved."
warn_if_credentials_are_invalid
end
Expand Down
5 changes: 1 addition & 4 deletions railties/lib/rails/commands/encrypted/encrypted_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ def ensure_encrypted_configuration_has_been_added

def change_encrypted_configuration_in_system_editor
catch_editing_exceptions do
encrypted_configuration.change do |tmp_path|
system("#{ENV["EDITOR"]} #{tmp_path}")
end

encrypted_configuration.change { |tmp_path| system_editor(tmp_path) }
say "File encrypted and saved."
warn_if_encrypted_configuration_is_invalid
end
Expand Down
2 changes: 1 addition & 1 deletion railties/test/commands/encrypted_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Rails::Command::EncryptedCommandTest < ActiveSupport::TestCase
test "edit command does not display save confirmation message if interrupted" do
assert_match %r/file encrypted and saved/i, run_edit_command

interrupt_command_process = %(exec ruby -e "Process.kill 'INT', Process.ppid")
interrupt_command_process = %(ruby -e "Process.kill 'INT', Process.ppid")
output = run_edit_command(editor: interrupt_command_process)

assert_no_match %r/file encrypted and saved/i, output
Expand Down

0 comments on commit 6b042ad

Please sign in to comment.