Skip to content

Commit 7511c28

Browse files
committed
Merge remote-tracking branch 'upstream/main' into issue-51882
2 parents 155d0af + e2ef1d6 commit 7511c28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+380
-211
lines changed

actioncable/lib/action_cable/connection/test_case.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,23 @@ def assert_reject_connection(&block)
3030
end
3131
end
3232

33+
class TestCookies < ActiveSupport::HashWithIndifferentAccess
34+
def []=(name, options)
35+
value = options.is_a?(Hash) ? options.symbolize_keys[:value] : options
36+
super(name, value)
37+
end
38+
end
39+
3340
# We don't want to use the whole "encryption stack" for connection unit-tests,
3441
# but we want to make sure that users test against the correct types of cookies
3542
# (i.e. signed or encrypted or plain)
36-
class TestCookieJar < ActiveSupport::HashWithIndifferentAccess
43+
class TestCookieJar < TestCookies
3744
def signed
38-
self[:signed] ||= {}.with_indifferent_access
45+
@signed ||= TestCookies.new
3946
end
4047

4148
def encrypted
42-
self[:encrypted] ||= {}.with_indifferent_access
49+
@encrypted ||= TestCookies.new
4350
end
4451
end
4552

actioncable/test/connection/test_case_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def test_plain_cookie
4747
assert_equal "456", connection.user_id
4848
end
4949

50+
def test_plain_cookie_with_explicit_value_and_string_key
51+
cookies["user_id"] = { "value" => "456" }
52+
53+
connect
54+
55+
assert_equal "456", connection.user_id
56+
end
57+
5058
def test_disconnect
5159
cookies["user_id"] = "456"
5260

@@ -133,6 +141,14 @@ def test_connected_with_encrypted_cookies
133141
assert_equal "456", connection.user_id
134142
end
135143

144+
def test_connected_with_encrypted_cookies_with_explicit_value_and_symbol_key
145+
cookies.encrypted["user_id"] = { value: "456" }
146+
147+
connect
148+
149+
assert_equal "456", connection.user_id
150+
end
151+
136152
def test_connection_rejected
137153
assert_reject_connection { connect }
138154
end

actionpack/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
* Add `:wasm_unsafe_eval` mapping for `content_security_policy`
2+
3+
```ruby
4+
# Before
5+
policy.script_src "'wasm-unsafe-eval'"
6+
7+
# After
8+
policy.script_src :wasm_unsafe_eval
9+
```
10+
11+
*Joe Haig*
112

213
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/actionpack/CHANGELOG.md) for previous changes.

actionpack/lib/action_dispatch/http/content_security_policy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def generate_content_security_policy_nonce
126126
MAPPINGS = {
127127
self: "'self'",
128128
unsafe_eval: "'unsafe-eval'",
129+
wasm_unsafe_eval: "'wasm-unsafe-eval'",
129130
unsafe_hashes: "'unsafe-hashes'",
130131
unsafe_inline: "'unsafe-inline'",
131132
none: "'none'",

actionpack/test/dispatch/content_security_policy_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def test_mappings
4545
@policy.script_src :unsafe_eval
4646
assert_equal "script-src 'unsafe-eval'", @policy.build
4747

48+
@policy.script_src :wasm_unsafe_eval
49+
assert_equal "script-src 'wasm-unsafe-eval'", @policy.build
50+
4851
@policy.script_src :none
4952
assert_equal "script-src 'none'", @policy.build
5053

actionview/lib/action_view/helpers/form_tag_helper.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,23 @@ def date_field_tag(name, value = nil, options = {})
747747
# * <tt>:max</tt> - The maximum acceptable value.
748748
# * <tt>:step</tt> - The acceptable value granularity.
749749
# * <tt>:include_seconds</tt> - Include seconds and ms in the output timestamp format (true by default).
750+
#
751+
# ==== Examples
752+
#
753+
# time_field_tag 'name'
754+
# # => <input id="name" name="name" type="time" />
755+
#
756+
# time_field_tag 'time', '01:01'
757+
# # => <input id="time" name="time" type="time" value="01:01" />
758+
#
759+
# time_field_tag 'time', nil, class: 'special_input'
760+
# # => <input class="special_input" id="time" name="time" type="time" />
761+
#
762+
# time_field_tag 'time', '01:01', include_seconds: true
763+
# # => <input id="time" name="time" type="time" value="01:01:00.000" />
764+
#
765+
# time_field_tag 'time', '01:01', min: '00:00', max: '23:59', step: 1
766+
# # => <input id="time" max="23:59" min="00:00" name="time" step="1" type="time" value="01:01" />
750767
def time_field_tag(name, value = nil, options = {})
751768
text_field_tag(name, value, options.merge(type: :time))
752769
end
@@ -761,6 +778,20 @@ def time_field_tag(name, value = nil, options = {})
761778
# * <tt>:max</tt> - The maximum acceptable value.
762779
# * <tt>:step</tt> - The acceptable value granularity.
763780
# * <tt>:include_seconds</tt> - Include seconds in the output timestamp format (true by default).
781+
#
782+
# ==== Examples
783+
#
784+
# datetime_field_tag 'name'
785+
# # => <input id="name" name="name" type="datetime-local" />
786+
#
787+
# datetime_field_tag 'datetime', '2014-01-01T01:01'
788+
# # => <input id="datetime" name="datetime" type="datetime-local" value="2014-01-01T01:01" />
789+
#
790+
# datetime_field_tag 'datetime', nil, class: 'special_input'
791+
# # => <input class="special_input" id="datetime" name="datetime" type="datetime-local" />
792+
#
793+
# datetime_field_tag 'datetime', '2014-01-01T01:01', class: 'special_input', disabled: true
794+
# # => <input disabled="disabled" class="special_input" id="datetime" name="datetime" type="datetime-local" value="2014-01-01T01:01" />
764795
def datetime_field_tag(name, value = nil, options = {})
765796
text_field_tag(name, value, options.merge(type: "datetime-local"))
766797
end
@@ -776,6 +807,20 @@ def datetime_field_tag(name, value = nil, options = {})
776807
# * <tt>:min</tt> - The minimum acceptable value.
777808
# * <tt>:max</tt> - The maximum acceptable value.
778809
# * <tt>:step</tt> - The acceptable value granularity.
810+
#
811+
# ==== Examples
812+
#
813+
# month_field_tag 'name'
814+
# # => <input id="name" name="name" type="month" />
815+
#
816+
# month_field_tag 'month', '2014-01'
817+
# # => <input id="month" name="month" type="month" value="2014-01" />
818+
#
819+
# month_field_tag 'month', nil, class: 'special_input'
820+
# # => <input class="special_input" id="month" name="month" type="month" />
821+
#
822+
# month_field_tag 'month', '2014-01', class: 'special_input', disabled: true
823+
# # => <input disabled="disabled" class="special_input" id="month" name="month" type="month" value="2014-01" />
779824
def month_field_tag(name, value = nil, options = {})
780825
text_field_tag(name, value, options.merge(type: :month))
781826
end
@@ -789,6 +834,20 @@ def month_field_tag(name, value = nil, options = {})
789834
# * <tt>:min</tt> - The minimum acceptable value.
790835
# * <tt>:max</tt> - The maximum acceptable value.
791836
# * <tt>:step</tt> - The acceptable value granularity.
837+
#
838+
# ==== Examples
839+
#
840+
# week_field_tag 'name'
841+
# # => <input id="name" name="name" type="week" />
842+
#
843+
# week_field_tag 'week', '2014-W01'
844+
# # => <input id="week" name="week" type="week" value="2014-W01" />
845+
#
846+
# week_field_tag 'week', nil, class: 'special_input'
847+
# # => <input class="special_input" id="week" name="week" type="week" />
848+
#
849+
# week_field_tag 'week', '2014-W01', class: 'special_input', disabled: true
850+
# # => <input disabled="disabled" class="special_input" id="week" name="week" type="week" value="2014-W01" />
792851
def week_field_tag(name, value = nil, options = {})
793852
text_field_tag(name, value, options.merge(type: :week))
794853
end
@@ -897,6 +956,17 @@ def number_field_tag(name, value = nil, options = {})
897956
# ==== Options
898957
#
899958
# Supports the same options as #number_field_tag.
959+
#
960+
# ==== Examples
961+
#
962+
# range_field_tag 'quantity', '1'
963+
# # => <input id="quantity" name="quantity" type="range" value="1" />
964+
#
965+
# range_field_tag 'quantity', in: 1...10
966+
# # => <input id="quantity" name="quantity" min="1" max="9" type="range" />
967+
#
968+
# range_field_tag 'quantity', min: 1, max: 10, step: 2
969+
# # => <input id="quantity" name="quantity" min="1" max="10" step="2" type="range"
900970
def range_field_tag(name, value = nil, options = {})
901971
number_field_tag(name, value, options.merge(type: :range))
902972
end

activerecord/lib/active_record/associations/collection_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def reset
9494
def find(*args)
9595
if options[:inverse_of] && loaded?
9696
args_flatten = args.flatten
97-
model = scope.klass
97+
model = scope.model
9898

9999
if args_flatten.blank?
100100
error_message = "Couldn't find #{model.name} without an ID"

activerecord/lib/active_record/associations/collection_proxy.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,20 @@ def include?(record)
928928
!!@association.include?(record)
929929
end
930930

931-
def proxy_association # :nodoc:
931+
# Returns the association object for the collection.
932+
#
933+
# class Person < ActiveRecord::Base
934+
# has_many :pets
935+
# end
936+
#
937+
# person.pets.proxy_association
938+
# # => #<ActiveRecord::Associations::HasManyAssociation owner="#<Person:0x00>">
939+
#
940+
# Returns the same object as <tt>person.association(:pets)</tt>,
941+
# allowing you to make calls like <tt>person.pets.proxy_association.owner</tt>.
942+
#
943+
# See Associations::ClassMethods@Association+extensions for more.
944+
def proxy_association
932945
@association
933946
end
934947

activerecord/lib/active_record/associations/disable_joins_association_scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def add_constraints(reflection, key, join_ids, owner, ordered)
4747
end
4848

4949
if scope.order_values.empty? && ordered
50-
split_scope = DisableJoinsAssociationRelation.create(scope.klass, key, join_ids)
50+
split_scope = DisableJoinsAssociationRelation.create(scope.model, key, join_ids)
5151
split_scope.where_clause += scope.where_clause
5252
split_scope
5353
else

activerecord/lib/active_record/associations/has_many_through_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def delete_records(records, method)
140140

141141
case method
142142
when :destroy
143-
if scope.klass.primary_key
143+
if scope.model.primary_key
144144
count = scope.destroy_all.count(&:destroyed?)
145145
else
146146
scope.each(&:_run_destroy_callbacks)

0 commit comments

Comments
 (0)