hanami-action 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfd2248b12d546b250ad80e1c7115aa23dbcfab93eb7620dca331a4939af34f0
4
- data.tar.gz: aa6a3f85fe8328a8e5d796be22b9d802cff6f74d643a8f1189f8cef89aafc3d8
3
+ metadata.gz: ead66d07305c1ab423774ef35b1aba0d6f280aa0d0921299f8daca4e4130e09e
4
+ data.tar.gz: 0ce91d088d253b5daa993c768ecb633bf128e411fb0257b2594dd8cefdd80b23
5
5
  SHA512:
6
- metadata.gz: 687db93c36b074e4015349842759091cbbb7fb35dda5f30ca1097cc629a1ee48767a2e3740ae54df491b4aee33e315b81e3e0e09a07b0fc0c37995f44c422a4f
7
- data.tar.gz: 29676466bb1d6aba7f7724aadc8c4bdc80f04d7c02bcb11414ad507e09fb623e628b75a23892b7fc10876a8141c180e49443cd503f61c26122196b7e89731088
6
+ metadata.gz: a48f8dac73391046b11a1236b98020c555f49d73251af2bb34a84198709e8e9365d80f1044a2f5089d9ba7656d479627a187fabaf094c045bb4325cad5d9e09a
7
+ data.tar.gz: a09c190e05396f4cf7ca9747109f961714ca164ff1cb7594319ff28b014278152ae0ac1ae319ca26e1726a7fb1abcaa8bbf355df24afc9eada5b453bb96a62a6
data/CHANGELOG.md CHANGED
@@ -19,7 +19,29 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
19
19
 
20
20
  ### Security
21
21
 
22
- [Unreleased]: https://github.com/hanami/hanami-action/compare/v3.0.0...HEAD
22
+ [Unreleased]: https://github.com/hanami/hanami-action/compare/v3.0.2...HEAD
23
+
24
+ ## [3.0.2] - 2026-11-24
25
+
26
+ ### Security
27
+
28
+ - Give route params precedence over query string and form body params with the same name in actions with a contract. Route params have Symbol keys and the others have String keys, so both were kept and the contract read the query or form value, letting `?id=2` override the `:id` in `/users/1`. (@parndt in GHSA-55j2-5pph-56mv)
29
+
30
+ [3.0.2]: https://github.com/hanami/hanami-action/compare/v3.0.1...v3.0.2
31
+
32
+ ## [3.0.1] - 2026-07-03
33
+
34
+ Adding an improvement that was originally intended for 3.0.0.
35
+
36
+ ### Added
37
+
38
+ - Support additional `Cache-Control` directives in `response.cache_control`: `:immutable`, `:must_understand`, `stale_while_revalidate:` (requires a duration) and `stale_if_error:` (requires a duration). (@timriley in #522)
39
+
40
+ ### Changed
41
+
42
+ - `response.cache_control` raises `ArgumentError` for unknown directives instead of silently dropping them. (@timriley in #522)
43
+
44
+ [3.0.1]: https://github.com/hanami/hanami-action/compare/v3.0.0...v3.0.1
23
45
 
24
46
  ## [3.0.0] - 2026-06-30
25
47
 
@@ -7,13 +7,30 @@ module Hanami
7
7
  #
8
8
  # @since 0.3.0
9
9
  # @api private
10
- VALUE_DIRECTIVES = %i[max_age s_maxage min_fresh max_stale].freeze
10
+ VALUE_DIRECTIVES = %i[
11
+ max_age
12
+ max_stale
13
+ min_fresh
14
+ s_maxage
15
+ stale_if_error
16
+ stale_while_revalidate
17
+ ].freeze
11
18
 
12
19
  # Cache-Control directives which are implicitly true
13
20
  #
14
21
  # @since 0.3.0
15
22
  # @api private
16
- NON_VALUE_DIRECTIVES = %i[public private no_cache no_store no_transform must_revalidate proxy_revalidate].freeze
23
+ NON_VALUE_DIRECTIVES = %i[
24
+ immutable
25
+ must_revalidate
26
+ must_understand
27
+ no_cache
28
+ no_store
29
+ no_transform
30
+ private
31
+ proxy_revalidate
32
+ public
33
+ ].freeze
17
34
 
18
35
  # Class representing value directives
19
36
  #
@@ -41,7 +58,7 @@ module Hanami
41
58
  # @since 0.3.0
42
59
  # @api private
43
60
  def valid?
44
- VALUE_DIRECTIVES.include? @name
61
+ VALUE_DIRECTIVES.include?(@name)
45
62
  end
46
63
  end
47
64
 
@@ -71,7 +88,7 @@ module Hanami
71
88
  # @since 0.3.0
72
89
  # @api private
73
90
  def valid?
74
- NON_VALUE_DIRECTIVES.include? @name
91
+ NON_VALUE_DIRECTIVES.include?(@name)
75
92
  end
76
93
  end
77
94
 
@@ -104,7 +121,11 @@ module Hanami
104
121
  # @since 0.3.0
105
122
  # @api private
106
123
  def <<(directive)
107
- @directives << directive if directive.valid?
124
+ unless directive.valid?
125
+ raise ArgumentError.new("Unknown cache control directive: #{directive.name.inspect}")
126
+ end
127
+
128
+ @directives << directive
108
129
  end
109
130
 
110
131
  # @since 0.3.0
@@ -324,14 +324,29 @@ module Hanami
324
324
  result = {}
325
325
  rack_request = ::Rack::Request.new(env) if has_query || has_form_body
326
326
 
327
- result.merge!(rack_request.GET) if has_query
328
- result.merge!(rack_request.POST) if has_form_body
329
- result.merge!(env[ROUTER_PARAMS]) if has_router_params
330
- result.merge!(env[ACTION_BODY_PARAMS]) if has_body_params
327
+ _merge_params(result, rack_request.GET) if has_query
328
+ _merge_params(result, rack_request.POST) if has_form_body
329
+ _merge_params(result, env[ROUTER_PARAMS]) if has_router_params
330
+ _merge_params(result, env[ACTION_BODY_PARAMS]) if has_body_params
331
331
 
332
332
  result
333
333
  end
334
334
 
335
+ # Merges params, replacing any existing value for the same key, whether it was stored with
336
+ # a String or a Symbol key. Route params have Symbol keys while the others have String keys,
337
+ # so without this a query or form param could sit alongside the route param it was meant to
338
+ # be overridden by, and a contract would read the query or form value instead.
339
+ def _merge_params(result, params)
340
+ params.each do |key, value|
341
+ if key.is_a?(Symbol)
342
+ result.delete(key.name)
343
+ elsif key.valid_encoding?
344
+ result.delete(key.to_sym)
345
+ end
346
+ result[key] = value
347
+ end
348
+ end
349
+
335
350
  def _form_content_type?(content_type)
336
351
  return false unless content_type
337
352
 
@@ -332,12 +332,17 @@ module Hanami
332
332
 
333
333
  # Specifies the response freshness policy for HTTP caches using the `Cache-Control` header.
334
334
  #
335
- # Any number of non-value directives (`:public`, `:private`, `:no_cache`, `:no_store`,
336
- # `:must_revalidate`, `:proxy_revalidate`) may be passed along with a Hash of value directives
337
- # (`:max_age`, `:min_stale`, `:s_max_age`).
335
+ # Directives come in two forms:
338
336
  #
339
- # See [RFC 2616 / 14.9](http://tools.ietf.org/html/rfc2616#section-14.9.1) for more on
340
- # standard cache control directives.
337
+ # - Non-value directives (such as `:public` or `:no_store`) are passed as bare symbols.
338
+ # - Value directives (such as `max_age:` or `s_maxage:`) are passed as a trailing Hash.
339
+ #
340
+ # See the `@option` entries below for the full set of supported directives. Passing an unknown
341
+ # directive raises an `ArgumentError`.
342
+ #
343
+ # See [MDN's Cache-Control reference][mdn] for more on the standard cache control directives.
344
+ #
345
+ # [mdn]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control
341
346
  #
342
347
  # @example
343
348
  # # Set Cache-Control directives
@@ -349,15 +354,21 @@ module Hanami
349
354
  # response.get_header("Cache-Control") # => "private, no-store, max-age=900"
350
355
  #
351
356
  # @param values [Array<Symbol, Hash>] values to map to `Cache-Control` directives
352
- # @option values [Symbol] :public
353
- # @option values [Symbol] :private
357
+ # @option values [Symbol] :immutable
358
+ # @option values [Symbol] :must_revalidate
359
+ # @option values [Symbol] :must_understand
354
360
  # @option values [Symbol] :no_cache
355
361
  # @option values [Symbol] :no_store
356
- # @option values [Symbol] :must_validate
362
+ # @option values [Symbol] :no_transform
363
+ # @option values [Symbol] :private
357
364
  # @option values [Symbol] :proxy_revalidate
365
+ # @option values [Symbol] :public
358
366
  # @option values [Hash] :max_age
359
- # @option values [Hash] :min_stale
360
- # @option values [Hash] :s_max_age
367
+ # @option values [Hash] :max_stale
368
+ # @option values [Hash] :min_fresh
369
+ # @option values [Hash] :s_maxage
370
+ # @option values [Hash] :stale_if_error
371
+ # @option values [Hash] :stale_while_revalidate
361
372
  #
362
373
  # @return void
363
374
  #
@@ -8,6 +8,6 @@ module Hanami
8
8
  #
9
9
  # @since 3.0.0
10
10
  # @api public
11
- VERSION = "3.0.0"
11
+ VERSION = "3.0.2"
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-action
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hanakai team