Skip to content

Commit 6b042ad

Browse files
Merge pull request rails#45708 from jonathanhefner/encrypted-config-tmp-path-with-spaces
Support spaces in file path when invoking editor
2 parents 0098f55 + 75d4e87 commit 6b042ad

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

railties/lib/rails/command/helpers/editor.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require "shellwords"
34
require "active_support/encrypted_file"
45

56
module Rails
@@ -22,6 +23,10 @@ def ensure_editor_available(command:)
2223
end
2324
end
2425

26+
def system_editor(file_path)
27+
system(*Shellwords.split(ENV["EDITOR"]), file_path.to_s)
28+
end
29+
2530
def catch_editing_exceptions
2631
yield
2732
rescue Interrupt

railties/lib/rails/commands/credentials/credentials_command.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "pathname"
4-
require "shellwords"
54
require "active_support"
65
require "rails/command/helpers/editor"
76
require "rails/command/environment_argument"
@@ -93,10 +92,7 @@ def ensure_credentials_have_been_added
9392

9493
def change_credentials_in_system_editor
9594
catch_editing_exceptions do
96-
credentials.change do |tmp_path|
97-
system(*Shellwords.split(ENV["EDITOR"]), tmp_path.to_s)
98-
end
99-
95+
credentials.change { |tmp_path| system_editor(tmp_path) }
10096
say "File encrypted and saved."
10197
warn_if_credentials_are_invalid
10298
end

railties/lib/rails/commands/encrypted/encrypted_command.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ def ensure_encrypted_configuration_has_been_added
6161

6262
def change_encrypted_configuration_in_system_editor
6363
catch_editing_exceptions do
64-
encrypted_configuration.change do |tmp_path|
65-
system("#{ENV["EDITOR"]} #{tmp_path}")
66-
end
67-
64+
encrypted_configuration.change { |tmp_path| system_editor(tmp_path) }
6865
say "File encrypted and saved."
6966
warn_if_encrypted_configuration_is_invalid
7067
end

railties/test/commands/encrypted_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Rails::Command::EncryptedCommandTest < ActiveSupport::TestCase
8585
test "edit command does not display save confirmation message if interrupted" do
8686
assert_match %r/file encrypted and saved/i, run_edit_command
8787

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

9191
assert_no_match %r/file encrypted and saved/i, output

0 commit comments

Comments
 (0)