Skip to content

Commit ba2a660

Browse files
authored
Merge pull request rails#46656 from Shopify/disable-irb-autocompletion-in-production
Disable Rails console IRB's autocompletion in production by default.
2 parents fe83b7f + de716b0 commit ba2a660

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

railties/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Rails console now disables `IRB`'s autocompletion feature in production by default.
2+
3+
Setting `IRB_USE_AUTOCOMPLETE=true` can override this default.
4+
5+
*Stan Lo*
6+
17
* Add `config.precompile_filter_parameters`, which enables precompilation of
28
`config.filter_parameters` using `ActiveSupport::ParameterFilter.precompile_filters`.
39
Precompilation can improve filtering performance, depending on the quantity

railties/lib/rails/commands/console/console_command.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def initialize(app, options = {})
3838

3939
if @console == IRB
4040
IRB::WorkSpace.prepend(BacktraceCleaner)
41+
42+
if Rails.env == "production"
43+
ENV["IRB_USE_AUTOCOMPLETE"] ||= "false"
44+
end
4145
end
4246
end
4347

railties/test/commands/console_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,45 @@ def test_console_defaults_to_IRB
5858
assert_equal IRB, Rails::Console.new(app).console
5959
end
6060

61+
def test_console_disables_IRB_auto_completion_in_production
62+
original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"]
63+
ENV["IRB_USE_AUTOCOMPLETE"] = nil
64+
65+
with_rack_env "production" do
66+
app = build_app(nil)
67+
assert_equal IRB, Rails::Console.new(app).console
68+
assert_equal "false", ENV["IRB_USE_AUTOCOMPLETE"]
69+
end
70+
ensure
71+
ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete
72+
end
73+
74+
def test_console_accepts_override_on_IRB_auto_completion_flag
75+
original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"]
76+
ENV["IRB_USE_AUTOCOMPLETE"] = "true"
77+
78+
with_rack_env "production" do
79+
app = build_app(nil)
80+
assert_equal IRB, Rails::Console.new(app).console
81+
assert_equal "true", ENV["IRB_USE_AUTOCOMPLETE"]
82+
end
83+
ensure
84+
ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete
85+
end
86+
87+
def test_console_doesnt_disable_IRB_auto_completion_in_non_production
88+
original_use_autocomplete = ENV["IRB_USE_AUTOCOMPLETE"]
89+
ENV["IRB_USE_AUTOCOMPLETE"] = nil
90+
91+
with_rails_env nil do
92+
app = build_app(nil)
93+
assert_equal IRB, Rails::Console.new(app).console
94+
assert_nil ENV["IRB_USE_AUTOCOMPLETE"]
95+
end
96+
ensure
97+
ENV["IRB_USE_AUTOCOMPLETE"] = original_use_autocomplete
98+
end
99+
61100
def test_default_environment_with_no_rails_env
62101
with_rails_env nil do
63102
start

0 commit comments

Comments
 (0)