roda 3.107.0 → 3.108.0

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/roda/plugins/_base64.rb +2 -2
  3. data/lib/roda/plugins/_optimized_matching.rb +1 -0
  4. data/lib/roda/plugins/all_verbs.rb +2 -2
  5. data/lib/roda/plugins/assets.rb +4 -4
  6. data/lib/roda/plugins/bearer_token.rb +2 -2
  7. data/lib/roda/plugins/break.rb +9 -1
  8. data/lib/roda/plugins/caching.rb +12 -12
  9. data/lib/roda/plugins/common_logger.rb +4 -4
  10. data/lib/roda/plugins/cookie_flags.rb +2 -2
  11. data/lib/roda/plugins/each_part.rb +4 -4
  12. data/lib/roda/plugins/error_email.rb +2 -2
  13. data/lib/roda/plugins/exception_page.rb +2 -2
  14. data/lib/roda/plugins/h.rb +4 -4
  15. data/lib/roda/plugins/hash_branches.rb +8 -4
  16. data/lib/roda/plugins/hash_paths.rb +4 -2
  17. data/lib/roda/plugins/hash_public.rb +2 -2
  18. data/lib/roda/plugins/hmac_paths.rb +27 -29
  19. data/lib/roda/plugins/host_routing.rb +29 -4
  20. data/lib/roda/plugins/invalid_request_body.rb +2 -0
  21. data/lib/roda/plugins/json_parser.rb +20 -2
  22. data/lib/roda/plugins/mail_processor.rb +2 -2
  23. data/lib/roda/plugins/mailer.rb +4 -4
  24. data/lib/roda/plugins/optimized_segment_matchers.rb +13 -6
  25. data/lib/roda/plugins/optimized_string_matchers.rb +6 -3
  26. data/lib/roda/plugins/params_capturing.rb +16 -7
  27. data/lib/roda/plugins/params_capturing_restore.rb +72 -0
  28. data/lib/roda/plugins/part.rb +4 -4
  29. data/lib/roda/plugins/pass.rb +4 -1
  30. data/lib/roda/plugins/path.rb +6 -6
  31. data/lib/roda/plugins/path_matchers.rb +5 -1
  32. data/lib/roda/plugins/public.rb +4 -4
  33. data/lib/roda/plugins/render.rb +24 -12
  34. data/lib/roda/plugins/render_coverage.rb +7 -6
  35. data/lib/roda/plugins/render_each.rb +2 -2
  36. data/lib/roda/plugins/route_csrf.rb +35 -3
  37. data/lib/roda/plugins/run_append_slash.rb +8 -4
  38. data/lib/roda/plugins/sec_fetch_site_csrf.rb +5 -2
  39. data/lib/roda/plugins/sessions.rb +2 -2
  40. data/lib/roda/plugins/shape_friendly.rb +4 -4
  41. data/lib/roda/plugins/static.rb +3 -0
  42. data/lib/roda/plugins/type_routing.rb +1 -1
  43. data/lib/roda/plugins/url_escape.rb +2 -2
  44. data/lib/roda/plugins/view_options.rb +3 -5
  45. data/lib/roda/plugins.rb +4 -4
  46. data/lib/roda/request.rb +25 -9
  47. data/lib/roda/version.rb +1 -1
  48. data/lib/roda.rb +7 -7
  49. metadata +2 -1
data/lib/roda/request.rb CHANGED
@@ -437,8 +437,15 @@ class Roda
437
437
 
438
438
  # Match the given hash if all hash matchers match.
439
439
  def _match_hash(hash)
440
+ rp = @remaining_path
441
+ captures_len = @captures.length
442
+
440
443
  # Allow calling private methods, as match methods are generally private
441
- hash.all?{|k,v| send("match_#{k}", v)}
444
+ return true if hash.all?{|k,v| send("match_#{k}", v)}
445
+
446
+ @remaining_path = rp
447
+ @captures.slice!(captures_len, 10000000)
448
+ false
442
449
  end
443
450
 
444
451
  # Match integer segment of up to 100 decimal characters, and yield resulting value as an
@@ -510,6 +517,7 @@ class Roda
510
517
  rp = @remaining_path
511
518
  if rp.getbyte(0) == 47
512
519
  if last = rp.index('/', 1)
520
+ return false if last == 1
513
521
  @captures << rp[1, last-1]
514
522
  @remaining_path = rp[last, rp.length]
515
523
  elsif (len = rp.length) > 1
@@ -568,12 +576,12 @@ class Roda
568
576
 
569
577
  if meth
570
578
  return unless captures = scope.send(meth, *captures)
571
- # :nocov:
579
+ # simplecov:disable
572
580
  # RODA4: Remove elsif block
573
581
  elsif defined?(yield)
574
582
  RodaPlugins.warn("Passing a block to RodaRequest#consume will be ignored in Roda 4. Update the code to pass a scope method symbol as the second argument.")
575
583
  return unless captures = yield(*captures)
576
- # :nocov:
584
+ # simplecov:enable
577
585
  end
578
586
 
579
587
  @remaining_path = matchdata.post_match
@@ -594,13 +602,13 @@ class Roda
594
602
  if regexp.match?(rp)
595
603
  if last = rp.index('/', 1)
596
604
  val = rp[1, last-1]
597
- @remaining_path = rp[last, rp.length]
605
+ new_rp = rp[last, rp.length]
598
606
  else
599
607
  val = rp[1, rp.length]
600
- @remaining_path = ""
608
+ new_rp = ""
601
609
  end
602
610
 
603
- if meth
611
+ ret = if meth
604
612
  if captures = scope.send(meth, val)
605
613
  if captures.is_a?(Array)
606
614
  @captures.concat(captures)
@@ -611,12 +619,16 @@ class Roda
611
619
  else
612
620
  @captures << val
613
621
  end
622
+
623
+ @remaining_path = new_rp if ret
624
+
625
+ ret
614
626
  end
615
627
  end
616
- # :nocov:
628
+ # simplecov:disable
617
629
  else
618
630
  alias _consume_single_segment consume
619
- # :nocov:
631
+ # simplecov:enable
620
632
  end
621
633
 
622
634
  # The default path to use for redirects when a path is not given.
@@ -627,9 +639,13 @@ class Roda
627
639
  #
628
640
  # If the current request is a GET request, raise an error, as otherwise
629
641
  # it is easy to create an infinite redirect.
642
+ #
643
+ # If the path starts +//+, then this redirects to the root path
644
+ # (+/+) instead of using a protocol-relative redirect.
630
645
  def default_redirect_path
631
646
  raise RodaError, "must provide path argument to redirect for get requests" if is_get?
632
- path
647
+ path = self.path
648
+ path.start_with?('//') ? '/' : path
633
649
  end
634
650
 
635
651
  # The default status to use for redirects if a status is not provided,
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 107
7
+ RodaMinorVersion = 108
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
data/lib/roda.rb CHANGED
@@ -142,9 +142,9 @@ class Roda
142
142
  block = if RUBY_VERSION >= '2.7'
143
143
  eval('lambda{|*a, **kw| instance_exec(*a, **kw, &b)}', nil, __FILE__, __LINE__) # Keyword arguments fallback
144
144
  else
145
- # :nocov:
145
+ # simplecov:disable
146
146
  lambda{|*a| instance_exec(*a, &b)} # Keyword arguments fallback
147
- # :nocov:
147
+ # simplecov:enable
148
148
  end
149
149
  else
150
150
  arity_meth = meth
@@ -226,7 +226,7 @@ class Roda
226
226
  plugin :direct_call
227
227
  end
228
228
 
229
- if RUBY_VERSION > "2.4" && ([:on, :is, :_verb, :_match_class_String, :_match_class_Integer, :_match_string, :_match_regexp, :empty_path?, :if_match, :match, :_match_class]).all?{|m| self::RodaRequest.instance_method(m).owner == RequestMethods}
229
+ if RUBY_VERSION > "2.4" && ([:on, :is, :_verb, :_match_class_String, :_match_class_Integer, :_match_string, :_match_regexp, :empty_path?, :if_match, :match, :_match_class, :always]).all?{|m| self::RodaRequest.instance_method(m).owner == RequestMethods}
230
230
  plugin :_optimized_matching
231
231
  end
232
232
  end
@@ -312,9 +312,9 @@ class Roda
312
312
  plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)
313
313
  @app = nil
314
314
  end
315
- # :nocov:
315
+ # simplecov:disable
316
316
  ruby2_keywords(:plugin) if respond_to?(:ruby2_keywords, true)
317
- # :nocov:
317
+ # simplecov:enable
318
318
 
319
319
  # Setup routing tree for the current Roda application, and build the
320
320
  # underlying rack application using the stored middleware. Requires
@@ -350,9 +350,9 @@ class Roda
350
350
  @middleware << [args, block].freeze
351
351
  @app = nil
352
352
  end
353
- # :nocov:
353
+ # simplecov:disable
354
354
  ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
355
- # :nocov:
355
+ # simplecov:enable
356
356
 
357
357
  private
358
358
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.107.0
4
+ version: 3.108.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -259,6 +259,7 @@ files:
259
259
  - lib/roda/plugins/padrino_render.rb
260
260
  - lib/roda/plugins/param_matchers.rb
261
261
  - lib/roda/plugins/params_capturing.rb
262
+ - lib/roda/plugins/params_capturing_restore.rb
262
263
  - lib/roda/plugins/part.rb
263
264
  - lib/roda/plugins/partials.rb
264
265
  - lib/roda/plugins/pass.rb