hanami-router 2.3.1 → 2.3.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: c9a6b9498cdc6f09a3792b52accbe0fda997f5de907fb0e523408a0a8437465c
4
- data.tar.gz: 40fc3193dcd6e471f1464852844456748f1ef8deb53ad630290e1343abdfbbbd
3
+ metadata.gz: 1f02aa739470dd4d899daf0b24a799e136b289cae1a29a0dcffe9a23ff058194
4
+ data.tar.gz: f03429f9ad782f1f231a9c0dee4d99ad976be9dfe2c628259b989b9f4a46d660
5
5
  SHA512:
6
- metadata.gz: b514e367ea3eb3b3be40f89d19b5a00388365b1a39fd0dc5bc98c1f971ff2831a4fcc80c3c463079d4a61773e0375504cfd9afa198aae7d1c42d762fb2e56def
7
- data.tar.gz: ef993a463b78db8deba2a6b6304aeb408961ee6ae89e92e62f8b79e52f662a6c0d7155921aee78c1ddce67055fa218294b09afefb19674d27aa1edb32622c0e8
6
+ metadata.gz: 75a2139a9afd3d62267181914bfdfbdffe54c5db6ac8fc8ab7a1079cd215655d878c7328fb43ebcb2424af4a923ab7e26fed4ec9feed84c4d70ba3f7bfc02948
7
+ data.tar.gz: c6271704409a32bab1e7ecc45f7c670d3dbb60484722d4a609f6ceec38ee977346ade97055f866d2d2b679899b290aa00ebaeab743f87476acaba69263875dcf
data/CHANGELOG.md CHANGED
@@ -16,7 +16,20 @@ Rack compatible HTTP router for Ruby.
16
16
 
17
17
  ### Security
18
18
 
19
- [Unreleased]: http://github.com/hanami/hanami-router/compare/v2.3.1...main
19
+ [Unreleased]: http://github.com/hanami/hanami-router/compare/v2.3.2...main
20
+
21
+ ## [2.3.2] - 2026-12-02
22
+
23
+ ### Fixed
24
+
25
+ - Fix a memory leak where the router kept every request path it received in memory. (@aaronmallen in #312)
26
+
27
+ ### Security
28
+
29
+ - Apply a scope's middleware to all of its paths when it contains a nested scope or slice with its own middleware. Previously, paths in the outer scope that weren't in the nested scope skipped the outer scope's middleware, such as authentication. (@parndt in GHSA-73j7-6jvw-2v7g)
30
+ - Stop concurrent requests to the same route from receiving each other's path params. Matching a route stored the captured params on the route itself, so a thread switch between matching and reading them could give one request another's params. (@parndt in GHSA-wgjv-fq27-94m7)
31
+
32
+ [2.3.2]: http://github.com/hanami/hanami-router/compare/v2.3.1...v2.3.2
20
33
 
21
34
  ## [2.3.1] - 2025-12-17
22
35
 
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-router.gemspec`.split($/)
18
18
  spec.executables = []
19
19
  spec.require_paths = ["lib"]
20
- spec.metadata["rubygems_mfa_required"] = "true"
21
20
  spec.required_ruby_version = ">= 3.2"
22
21
 
23
22
  spec.add_dependency "rack", ">= 2.2.16"
@@ -60,7 +60,7 @@ module Hanami
60
60
  parsers.each_with_object(registry) do |spec, memo|
61
61
  if spec.is_a?(Hash) && spec.size > 1
62
62
  spec.each do |key, value|
63
- build_parsers([key => [value]], memo)
63
+ build_parsers([{key => [value]}], memo)
64
64
  end
65
65
  else
66
66
  name, *media_types = Array(*spec).flatten(0)
@@ -59,7 +59,7 @@ module Hanami
59
59
  # raise Hanami::Middleware::BodyParser::BodyParsingError.new(exception.message)
60
60
  # end
61
61
  # end
62
- def parse(body, env = {}) # rubocop:disable Lint/UnusedMethodArgument
62
+ def parse(body, env = {})
63
63
  raise NoMethodError
64
64
  end
65
65
  end
@@ -38,16 +38,19 @@ module Hanami
38
38
  # @since 2.0.0
39
39
  def find(path)
40
40
  node = @root
41
+ app = @root.app
41
42
 
43
+ # Track the deepest scope with an app on the way down. When the descent stops early (a
44
+ # segment with no matching child under a node that has children), the request is still
45
+ # within that scope, so its middleware must apply.
42
46
  for_each_segment(path) do |segment|
47
+ node = node.get(segment)
43
48
  break unless node
44
49
 
45
- node = node.get(segment)
50
+ app = node.app if node.app?
46
51
  end
47
52
 
48
- return node.app if node&.app?
49
-
50
- @root.app || @app
53
+ app || @app
51
54
  end
52
55
 
53
56
  # @api private
@@ -9,24 +9,24 @@ module Hanami
9
9
  #
10
10
  # @api private
11
11
  # @since 2.2.0
12
- attr_reader :to, :params, :matcher
12
+ attr_reader :to, :matcher
13
13
 
14
14
  # @api private
15
15
  # @since 2.2.0
16
16
  def initialize(route, to, constraints)
17
17
  @to = to
18
- @params = nil
19
18
  @matcher = Mustermann.new(route, type: :rails, version: "5.0", capture: constraints)
20
19
  end
21
20
 
21
+ # Returns the captured params for the given path, or nil if the path doesn't match.
22
+ #
23
+ # Leaves are shared across concurrent requests, so the captures are returned rather than
24
+ # stored on the leaf.
25
+ #
22
26
  # @api private
23
27
  # @since 2.2.0
24
28
  def match(path)
25
- match = matcher.match(path)
26
-
27
- @params = match.named_captures if match
28
-
29
- match
29
+ matcher.match(path)&.named_captures
30
30
  end
31
31
  end
32
32
  end
@@ -45,10 +45,17 @@ module Hanami
45
45
  @leaves << Leaf.new(route, to, constraints)
46
46
  end
47
47
 
48
+ # Returns the endpoint and captured params of the first leaf matching the given path, or nil.
49
+ #
48
50
  # @api private
49
51
  # @since 2.2.0
50
52
  def match(path)
51
- @leaves&.find { |leaf| leaf.match(path) }
53
+ @leaves&.each do |leaf|
54
+ params = leaf.match(path)
55
+ return [leaf.to, params] if params
56
+ end
57
+
58
+ nil
52
59
  end
53
60
 
54
61
  private
@@ -63,7 +63,7 @@ module Hanami
63
63
 
64
64
  # @api private
65
65
  # @since 2.0.0
66
- def initialize(http_method:, path:, to:, as: nil, constraints: {}, blk: nil) # rubocop:disable Metrics/ParameterLists
66
+ def initialize(http_method:, path:, to:, as: nil, constraints: {}, blk: nil)
67
67
  @http_method = http_method
68
68
  @path = path
69
69
  @to = to
@@ -17,7 +17,6 @@ module Hanami
17
17
  # @since 2.0.0
18
18
  def initialize
19
19
  @root = Node.new
20
- @segments_map = {}
21
20
  end
22
21
 
23
22
  # @api private
@@ -41,7 +40,7 @@ module Hanami
41
40
 
42
41
  return unless segments.all? { |segment| node = node.get(segment) }
43
42
 
44
- node.match(path)&.then { |found| [found.to, found.params] }
43
+ node.match(path)
45
44
  end
46
45
 
47
46
  private
@@ -54,12 +53,8 @@ module Hanami
54
53
  # @api private
55
54
  # @since 2.2.0
56
55
  def segments_from(path)
57
- if @segments_map[path]
58
- @segments_map[path]
59
- else
60
- _, *segments = path.split(SEGMENT_SEPARATOR)
61
- @segments_map[path] = segments
62
- end
56
+ _, *segments = path.split(SEGMENT_SEPARATOR)
57
+ segments
63
58
  end
64
59
  end
65
60
  end
@@ -8,6 +8,6 @@ module Hanami
8
8
  #
9
9
  # @since 0.1.0
10
10
  # @api public
11
- VERSION = "2.3.1"
11
+ VERSION = "2.3.2"
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hanakai team
@@ -194,8 +194,7 @@ files:
194
194
  homepage: http://hanamirb.org
195
195
  licenses:
196
196
  - MIT
197
- metadata:
198
- rubygems_mfa_required: 'true'
197
+ metadata: {}
199
198
  rdoc_options: []
200
199
  require_paths:
201
200
  - lib