aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-05-28 17:19:43 +0200
committerGitHub <noreply@github.com>2017-05-28 17:19:43 +0200
commit17223043959dfbd3b23646b7db01cf3119ad7943 (patch)
tree2333aaec7a928081b05bf23ecd1e6f0e2a1754b5 /railties
parent41c040ad25c864ec589e023e445c3b5ae2ab2de4 (diff)
parent7a154ab380501050e6ce20463de8f702353bceb0 (diff)
downloadrails-17223043959dfbd3b23646b7db01cf3119ad7943.tar.gz
rails-17223043959dfbd3b23646b7db01cf3119ad7943.tar.bz2
rails-17223043959dfbd3b23646b7db01cf3119ad7943.zip
Merge pull request #29146 from y-yagi/fix_29138
Correctly set user_supplied_options when there is no whitespace in option specification
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands/server/server_command.rb11
-rw-r--r--railties/test/commands/server_test.rb6
2 files changed, 15 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index cf3903f3ae..ebb4ae795a 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -155,9 +155,16 @@ module Rails
def user_supplied_options
@user_supplied_options ||= begin
# Convert incoming options array to a hash of flags
- # ["-p", "3001", "-c", "foo"] # => {"-p" => true, "-c" => true}
+ # ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true}
user_flag = {}
- @original_options.each_with_index { |command, i| user_flag[command] = true if i.even? }
+ @original_options.each do |command|
+ if command.to_s.start_with?("--")
+ option = command.split("=")[0]
+ user_flag[option] = true
+ elsif command =~ /\A(-.)/
+ user_flag[Regexp.last_match[0]] = true
+ end
+ end
# Collect all options that the user has explicitly defined so we can
# differentiate them from defaults
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index 7731d10d9b..722323efdc 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -165,6 +165,12 @@ class Rails::ServerTest < ActiveSupport::TestCase
server_options = parse_arguments(["--port", 3001])
assert_equal [:Port], server_options[:user_supplied_options]
+
+ server_options = parse_arguments(["-p3001", "-C", "--binding", "127.0.0.1"])
+ assert_equal [:Port, :Host, :caching], server_options[:user_supplied_options]
+
+ server_options = parse_arguments(["--port=3001"])
+ assert_equal [:Port], server_options[:user_supplied_options]
end
def test_default_options