Skip to content

Commit 2194198

Browse files
authored
Merge pull request #272 from danielfone/fix-string-mutation-in-form-group
Prevent mutating (possibly) frozen strings
2 parents 67e846f + 6eba354 commit 2194198

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Bugfixes:
44

55
- Minor README corrections (#184, @msmithstubbs)
66
- Fix `alias_method_chain` deprecation warnings when using Rails 5
7+
- Allow `form_group` to work with frozen string options
78

89
Features:
910

lib/bootstrap_form/form_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ def form_group(*args, &block)
198198
control.concat(generate_icon(options[:icon])) if options[:icon]
199199

200200
if get_group_layout(options[:layout]) == :horizontal
201-
control_class = (options[:control_col] || control_col.clone)
201+
control_class = options[:control_col] || control_col
202202
unless options[:label]
203203
control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || @label_col))
204-
control_class.concat(" #{control_offset}")
204+
control_class = "#{control_class} #{control_offset}"
205205
end
206206
control = content_tag(:div, control, class: control_class)
207207
end

test/bootstrap_form_group_test.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,13 @@ def setup
267267

268268
expected = %{<div class="form-group"><div class="col-sm-9 col-sm-offset-3"><p class="form-control-static">Bar</p></div></div>}
269269
assert_equal expected, output
270-
end
270+
end
271+
272+
test "non-default column span on form isn't mutated" do
273+
frozen_horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-3".freeze, control_col: "col-sm-9".freeze })
274+
output = frozen_horizontal_builder.form_group { 'test' }
275+
276+
expected = %{<div class="form-group"><div class="col-sm-9 col-sm-offset-3">test</div></div>}
277+
assert_equal expected, output
278+
end
271279
end

0 commit comments

Comments
 (0)