Skip to content

Commit fac3f20

Browse files
authored
Merge pull request rails#50904 from williantenfen/support-comments-on-railsrc-file
Commented out lines in .railsrc file should not be treated as arguments
2 parents e7073e4 + 35f132e commit fac3f20

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

railties/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Commented out lines in .railsrc file should not be treated as arguments when using
2+
rails new generator command. Update ARGVScrubber to ignore text after # symbols.
3+
4+
*Willian Tenfen*
5+
16
* Skip CSS when generating APIs.
27

38
*Ruy Rocha*

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def railsrc(argv)
658658
end
659659

660660
def read_rc_file(railsrc)
661-
extra_args = File.readlines(railsrc).flat_map(&:split)
661+
extra_args = File.readlines(railsrc).flat_map.each { |line| line.split("#", 2).first.split }
662662
puts "Using #{extra_args.join(" ")} from #{railsrc}"
663663
extra_args
664664
end

railties/test/generators/argv_scrubber_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ def test_rc_whitespace_separated
108108
file.unlink
109109
end
110110

111+
def test_rc_lines_with_comments
112+
file = Tempfile.new "myrcfile"
113+
file.puts "--hello # --world"
114+
file.puts "--love"
115+
file.puts "# --hate"
116+
file.flush
117+
118+
scrubber = Class.new(ARGVScrubber) {
119+
define_method(:puts) { |msg| }
120+
}.new ["new", "--rc=#{file.path}"]
121+
args = scrubber.prepare!
122+
assert_equal ["--hello", "--love"], args
123+
ensure
124+
file.close
125+
file.unlink
126+
end
127+
111128
def test_new_rc_option
112129
file = Tempfile.new "myrcfile"
113130
file.puts "--hello-world"

0 commit comments

Comments
 (0)