0001-Add-a-randomized-name-attribute-to-all-form-fields.patch

Holger Just, 2017-08-01 19:26

Download (1.96 KB)

View differences:

app/helpers/application_helper.rb
1180 1180
    fields_for(*args, &proc)
1181 1181
  end
1182 1182

  
1183
  def form_tag_html(html_options)
1184
    # Set a randomized name attribute on all form fields by default
1185
    # as a workaround to https://bugzilla.mozilla.org/show_bug.cgi?id=1279253
1186
    html_options['name'] ||= "#{html_options['id'] || 'form'}-#{SecureRandom.hex(4)}"
1187
    super
1188
  end
1189

  
1183 1190
  # Render the error messages for the given objects
1184 1191
  def error_messages_for(*objects)
1185 1192
    objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
test/helpers/application_helper_test.rb
1579 1579
    assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>', html_hours('0:45')
1580 1580
    assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">.75</span>', html_hours('0.75')
1581 1581
  end
1582

  
1583
  def test_form_for_includes_name_attribute
1584
    assert_match(/name="new_issue-[a-z0-9]{8}"/, form_for(Issue.new){})
1585
  end
1586

  
1587
  def test_labelled_form_for_includes_name_attribute
1588
    assert_match(/name="new_issue-[a-z0-9]{8}"/, labelled_form_for(Issue.new){})
1589
  end
1590

  
1582 1591
end
1583
-