actionpack 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (128) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +189 -1002
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/abstract_controller.rb +3 -3
  6. data/lib/abstract_controller/base.rb +10 -12
  7. data/lib/abstract_controller/caching.rb +6 -3
  8. data/lib/abstract_controller/caching/fragments.rb +1 -1
  9. data/lib/abstract_controller/callbacks.rb +2 -43
  10. data/lib/abstract_controller/collector.rb +2 -2
  11. data/lib/abstract_controller/helpers.rb +19 -19
  12. data/lib/abstract_controller/rendering.rb +9 -11
  13. data/lib/abstract_controller/translation.rb +3 -3
  14. data/lib/action_controller.rb +15 -13
  15. data/lib/action_controller/api.rb +3 -3
  16. data/lib/action_controller/base.rb +7 -12
  17. data/lib/action_controller/caching.rb +1 -1
  18. data/lib/action_controller/log_subscriber.rb +2 -2
  19. data/lib/action_controller/metal.rb +34 -43
  20. data/lib/action_controller/metal/conditional_get.rb +10 -9
  21. data/lib/action_controller/metal/data_streaming.rb +8 -9
  22. data/lib/action_controller/metal/etag_with_flash.rb +16 -0
  23. data/lib/action_controller/metal/etag_with_template_digest.rb +15 -15
  24. data/lib/action_controller/metal/exceptions.rb +4 -14
  25. data/lib/action_controller/metal/flash.rb +1 -1
  26. data/lib/action_controller/metal/force_ssl.rb +6 -6
  27. data/lib/action_controller/metal/head.rb +13 -19
  28. data/lib/action_controller/metal/helpers.rb +6 -6
  29. data/lib/action_controller/metal/http_authentication.rb +22 -23
  30. data/lib/action_controller/metal/implicit_render.rb +2 -5
  31. data/lib/action_controller/metal/instrumentation.rb +14 -14
  32. data/lib/action_controller/metal/live.rb +15 -16
  33. data/lib/action_controller/metal/mime_responds.rb +3 -3
  34. data/lib/action_controller/metal/parameter_encoding.rb +49 -0
  35. data/lib/action_controller/metal/params_wrapper.rb +32 -32
  36. data/lib/action_controller/metal/redirecting.rb +8 -24
  37. data/lib/action_controller/metal/renderers.rb +2 -3
  38. data/lib/action_controller/metal/rendering.rb +50 -60
  39. data/lib/action_controller/metal/request_forgery_protection.rb +51 -49
  40. data/lib/action_controller/metal/rescue.rb +1 -1
  41. data/lib/action_controller/metal/streaming.rb +4 -4
  42. data/lib/action_controller/metal/strong_parameters.rb +117 -250
  43. data/lib/action_controller/metal/testing.rb +1 -1
  44. data/lib/action_controller/metal/url_for.rb +4 -4
  45. data/lib/action_controller/railtie.rb +9 -13
  46. data/lib/action_controller/renderer.rb +17 -16
  47. data/lib/action_controller/test_case.rb +75 -148
  48. data/lib/action_dispatch.rb +20 -19
  49. data/lib/action_dispatch/http/cache.rb +9 -10
  50. data/lib/action_dispatch/http/filter_parameters.rb +8 -8
  51. data/lib/action_dispatch/http/filter_redirect.rb +2 -4
  52. data/lib/action_dispatch/http/headers.rb +10 -10
  53. data/lib/action_dispatch/http/mime_negotiation.rb +17 -22
  54. data/lib/action_dispatch/http/mime_type.rb +27 -52
  55. data/lib/action_dispatch/http/parameter_filter.rb +8 -6
  56. data/lib/action_dispatch/http/parameters.rb +40 -17
  57. data/lib/action_dispatch/http/request.rb +38 -34
  58. data/lib/action_dispatch/http/response.rb +16 -16
  59. data/lib/action_dispatch/http/upload.rb +6 -10
  60. data/lib/action_dispatch/http/url.rb +48 -74
  61. data/lib/action_dispatch/journey.rb +5 -5
  62. data/lib/action_dispatch/journey/formatter.rb +8 -4
  63. data/lib/action_dispatch/journey/gtg/builder.rb +5 -5
  64. data/lib/action_dispatch/journey/gtg/simulator.rb +1 -1
  65. data/lib/action_dispatch/journey/gtg/transition_table.rb +15 -15
  66. data/lib/action_dispatch/journey/nfa/builder.rb +3 -3
  67. data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
  68. data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
  69. data/lib/action_dispatch/journey/nfa/transition_table.rb +2 -2
  70. data/lib/action_dispatch/journey/nodes/node.rb +5 -5
  71. data/lib/action_dispatch/journey/parser.rb +23 -24
  72. data/lib/action_dispatch/journey/parser.y +3 -2
  73. data/lib/action_dispatch/journey/parser_extras.rb +2 -2
  74. data/lib/action_dispatch/journey/path/pattern.rb +10 -3
  75. data/lib/action_dispatch/journey/route.rb +19 -12
  76. data/lib/action_dispatch/journey/router.rb +19 -12
  77. data/lib/action_dispatch/journey/router/utils.rb +9 -9
  78. data/lib/action_dispatch/journey/scanner.rb +17 -15
  79. data/lib/action_dispatch/journey/visitors.rb +23 -23
  80. data/lib/action_dispatch/middleware/callbacks.rb +0 -12
  81. data/lib/action_dispatch/middleware/cookies.rb +39 -39
  82. data/lib/action_dispatch/middleware/debug_exceptions.rb +126 -112
  83. data/lib/action_dispatch/middleware/debug_locks.rb +8 -8
  84. data/lib/action_dispatch/middleware/exception_wrapper.rb +55 -55
  85. data/lib/action_dispatch/middleware/executor.rb +1 -1
  86. data/lib/action_dispatch/middleware/flash.rb +17 -16
  87. data/lib/action_dispatch/middleware/public_exceptions.rb +20 -20
  88. data/lib/action_dispatch/middleware/reloader.rb +3 -47
  89. data/lib/action_dispatch/middleware/remote_ip.rb +6 -8
  90. data/lib/action_dispatch/middleware/request_id.rb +6 -5
  91. data/lib/action_dispatch/middleware/session/abstract_store.rb +14 -26
  92. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  93. data/lib/action_dispatch/middleware/session/cookie_store.rb +35 -35
  94. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +2 -2
  95. data/lib/action_dispatch/middleware/show_exceptions.rb +19 -19
  96. data/lib/action_dispatch/middleware/ssl.rb +9 -27
  97. data/lib/action_dispatch/middleware/stack.rb +7 -26
  98. data/lib/action_dispatch/middleware/static.rb +13 -24
  99. data/lib/action_dispatch/railtie.rb +9 -11
  100. data/lib/action_dispatch/request/session.rb +22 -22
  101. data/lib/action_dispatch/request/utils.rb +11 -2
  102. data/lib/action_dispatch/routing.rb +8 -6
  103. data/lib/action_dispatch/routing/inspector.rb +37 -37
  104. data/lib/action_dispatch/routing/mapper.rb +296 -203
  105. data/lib/action_dispatch/routing/polymorphic_routes.rb +160 -134
  106. data/lib/action_dispatch/routing/redirection.rb +27 -22
  107. data/lib/action_dispatch/routing/route_set.rb +206 -92
  108. data/lib/action_dispatch/routing/routes_proxy.rb +2 -2
  109. data/lib/action_dispatch/routing/url_for.rb +14 -12
  110. data/lib/action_dispatch/system_test_case.rb +119 -0
  111. data/lib/action_dispatch/system_testing/browser.rb +28 -0
  112. data/lib/action_dispatch/system_testing/driver.rb +18 -0
  113. data/lib/action_dispatch/system_testing/server.rb +32 -0
  114. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +61 -0
  115. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +20 -0
  116. data/lib/action_dispatch/testing/assertion_response.rb +6 -6
  117. data/lib/action_dispatch/testing/assertions.rb +4 -4
  118. data/lib/action_dispatch/testing/assertions/response.rb +8 -3
  119. data/lib/action_dispatch/testing/assertions/routing.rb +11 -11
  120. data/lib/action_dispatch/testing/integration.rb +47 -138
  121. data/lib/action_dispatch/testing/test_process.rb +2 -2
  122. data/lib/action_dispatch/testing/test_request.rb +16 -16
  123. data/lib/action_dispatch/testing/test_response.rb +1 -1
  124. data/lib/action_pack.rb +2 -2
  125. data/lib/action_pack/gem_version.rb +3 -3
  126. data/lib/action_pack/version.rb +1 -1
  127. metadata +20 -12
  128. data/lib/action_dispatch/middleware/params_parser.rb +0 -46
@@ -1,4 +1,4 @@
1
- require 'strscan'
1
+ require "strscan"
2
2
 
3
3
  module ActionDispatch
4
4
  module Journey # :nodoc:
@@ -1,4 +1,4 @@
1
- require 'action_dispatch/journey/nfa/dot'
1
+ require "action_dispatch/journey/nfa/dot"
2
2
 
3
3
  module ActionDispatch
4
4
  module Journey # :nodoc:
@@ -10,7 +10,7 @@ module ActionDispatch
10
10
  attr_reader :memos
11
11
 
12
12
  def initialize
13
- @table = Hash.new { |h,f| h[f] = {} }
13
+ @table = Hash.new { |h, f| h[f] = {} }
14
14
  @memos = {}
15
15
  @accepting = nil
16
16
  @inverted = nil
@@ -1,4 +1,4 @@
1
- require 'action_dispatch/journey/visitors'
1
+ require "action_dispatch/journey/visitors"
2
2
 
3
3
  module ActionDispatch
4
4
  module Journey # :nodoc:
@@ -18,7 +18,7 @@ module ActionDispatch
18
18
  end
19
19
 
20
20
  def to_s
21
- Visitors::String::INSTANCE.accept(self, '')
21
+ Visitors::String::INSTANCE.accept(self, "")
22
22
  end
23
23
 
24
24
  def to_dot
@@ -30,7 +30,7 @@ module ActionDispatch
30
30
  end
31
31
 
32
32
  def name
33
- left.tr '*:'.freeze, ''.freeze
33
+ left.tr "*:".freeze, "".freeze
34
34
  end
35
35
 
36
36
  def type
@@ -80,7 +80,7 @@ module ActionDispatch
80
80
  def initialize(left)
81
81
  super
82
82
  @regexp = DEFAULT_EXP
83
- @name = left.tr '*:'.freeze, ''.freeze
83
+ @name = left.tr "*:".freeze, "".freeze
84
84
  end
85
85
 
86
86
  def default_regexp?
@@ -104,7 +104,7 @@ module ActionDispatch
104
104
  def type; :STAR; end
105
105
 
106
106
  def name
107
- left.name.tr '*:', ''
107
+ left.name.tr "*:", ""
108
108
  end
109
109
  end
110
110
 
@@ -1,33 +1,33 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.11
4
- # from Racc grammer file "".
3
+ # This file is automatically generated by Racc 1.4.14
4
+ # from Racc grammar file "".
5
5
  #
6
6
 
7
7
  require 'racc/parser.rb'
8
8
 
9
+ # :stopdoc:
9
10
 
10
- require 'action_dispatch/journey/parser_extras'
11
+ require "action_dispatch/journey/parser_extras"
11
12
  module ActionDispatch
12
- # :stopdoc:
13
13
  module Journey
14
14
  class Parser < Racc::Parser
15
15
  ##### State transition tables begin ###
16
16
 
17
17
  racc_action_table = [
18
- 13, 15, 14, 7, 21, 16, 8, 19, 13, 15,
19
- 14, 7, 17, 16, 8, 13, 15, 14, 7, 24,
20
- 16, 8, 13, 15, 14, 7, 19, 16, 8 ]
18
+ 13, 15, 14, 7, 19, 16, 8, 19, 13, 15,
19
+ 14, 7, 17, 16, 8, 13, 15, 14, 7, 21,
20
+ 16, 8, 13, 15, 14, 7, 24, 16, 8 ]
21
21
 
22
22
  racc_action_check = [
23
- 2, 2, 2, 2, 17, 2, 2, 2, 0, 0,
24
- 0, 0, 1, 0, 0, 19, 19, 19, 19, 20,
25
- 19, 19, 7, 7, 7, 7, 22, 7, 7 ]
23
+ 2, 2, 2, 2, 22, 2, 2, 2, 19, 19,
24
+ 19, 19, 1, 19, 19, 7, 7, 7, 7, 17,
25
+ 7, 7, 0, 0, 0, 0, 20, 0, 0 ]
26
26
 
27
27
  racc_action_pointer = [
28
- 6, 12, -2, nil, nil, nil, nil, 20, nil, nil,
29
- nil, nil, nil, nil, nil, nil, nil, 4, nil, 13,
30
- 13, nil, 17, nil, nil ]
28
+ 20, 12, -2, nil, nil, nil, nil, 13, nil, nil,
29
+ nil, nil, nil, nil, nil, nil, nil, 19, nil, 6,
30
+ 20, nil, -5, nil, nil ]
31
31
 
32
32
  racc_action_default = [
33
33
  -19, -19, -2, -3, -4, -5, -6, -19, -10, -11,
@@ -135,11 +135,11 @@ Racc_debug_parser = false
135
135
  # reduce 0 omitted
136
136
 
137
137
  def _reduce_1(val, _values)
138
- Cat.new(val.first, val.last)
138
+ Cat.new(val.first, val.last)
139
139
  end
140
140
 
141
141
  def _reduce_2(val, _values)
142
- val.first
142
+ val.first
143
143
  end
144
144
 
145
145
  # reduce 3 omitted
@@ -151,19 +151,19 @@ end
151
151
  # reduce 6 omitted
152
152
 
153
153
  def _reduce_7(val, _values)
154
- Group.new(val[1])
154
+ Group.new(val[1])
155
155
  end
156
156
 
157
157
  def _reduce_8(val, _values)
158
- Or.new([val.first, val.last])
158
+ Or.new([val.first, val.last])
159
159
  end
160
160
 
161
161
  def _reduce_9(val, _values)
162
- Or.new([val.first, val.last])
162
+ Or.new([val.first, val.last])
163
163
  end
164
164
 
165
165
  def _reduce_10(val, _values)
166
- Star.new(Symbol.new(val.last))
166
+ Star.new(Symbol.new(val.last))
167
167
  end
168
168
 
169
169
  # reduce 11 omitted
@@ -175,19 +175,19 @@ end
175
175
  # reduce 14 omitted
176
176
 
177
177
  def _reduce_15(val, _values)
178
- Slash.new('/')
178
+ Slash.new(val.first)
179
179
  end
180
180
 
181
181
  def _reduce_16(val, _values)
182
- Symbol.new(val.first)
182
+ Symbol.new(val.first)
183
183
  end
184
184
 
185
185
  def _reduce_17(val, _values)
186
- Literal.new(val.first)
186
+ Literal.new(val.first)
187
187
  end
188
188
 
189
189
  def _reduce_18(val, _values)
190
- Dot.new(val.first)
190
+ Dot.new(val.first)
191
191
  end
192
192
 
193
193
  def _reduce_none(val, _values)
@@ -196,5 +196,4 @@ end
196
196
 
197
197
  end # class Parser
198
198
  end # module Journey
199
- # :startdoc:
200
199
  end # module ActionDispatch
@@ -30,7 +30,7 @@ rule
30
30
  | dot
31
31
  ;
32
32
  slash
33
- : SLASH { Slash.new('/') }
33
+ : SLASH { Slash.new(val.first) }
34
34
  ;
35
35
  symbol
36
36
  : SYMBOL { Symbol.new(val.first) }
@@ -45,5 +45,6 @@ rule
45
45
  end
46
46
 
47
47
  ---- header
48
+ # :stopdoc:
48
49
 
49
- require 'action_dispatch/journey/parser_extras'
50
+ require "action_dispatch/journey/parser_extras"
@@ -1,5 +1,5 @@
1
- require 'action_dispatch/journey/scanner'
2
- require 'action_dispatch/journey/nodes/node'
1
+ require "action_dispatch/journey/scanner"
2
+ require "action_dispatch/journey/nodes/node"
3
3
 
4
4
  module ActionDispatch
5
5
  # :stopdoc:
@@ -4,7 +4,7 @@ module ActionDispatch
4
4
  class Pattern # :nodoc:
5
5
  attr_reader :spec, :requirements, :anchored
6
6
 
7
- def self.from_string string
7
+ def self.from_string(string)
8
8
  build(string, {}, "/.?", true)
9
9
  end
10
10
 
@@ -31,6 +31,13 @@ module ActionDispatch
31
31
  Visitors::FormatBuilder.new.accept(spec)
32
32
  end
33
33
 
34
+ def eager_load!
35
+ required_names
36
+ offsets
37
+ to_regexp
38
+ nil
39
+ end
40
+
34
41
  def ast
35
42
  @spec.find_all(&:symbol?).each do |node|
36
43
  re = @requirements[node.to_sym]
@@ -98,7 +105,7 @@ module ActionDispatch
98
105
  end
99
106
 
100
107
  def visit_STAR(node)
101
- re = @matchers[node.left.to_sym] || '.+'
108
+ re = @matchers[node.left.to_sym] || ".+"
102
109
  "(#{re})"
103
110
  end
104
111
 
@@ -175,7 +182,7 @@ module ActionDispatch
175
182
 
176
183
  if @requirements.key?(node)
177
184
  re = /#{@requirements[node]}|/
178
- @offsets.push((re.match('').length - 1) + @offsets.last)
185
+ @offsets.push((re.match("").length - 1) + @offsets.last)
179
186
  else
180
187
  @offsets << @offsets.last
181
188
  end
@@ -30,16 +30,15 @@ module ActionDispatch
30
30
 
31
31
  class All
32
32
  def self.call(_); true; end
33
- def self.verb; ''; end
33
+ def self.verb; ""; end
34
34
  end
35
35
 
36
- VERB_TO_CLASS = VERBS.each_with_object({ :all => All }) do |verb, hash|
36
+ VERB_TO_CLASS = VERBS.each_with_object(all: All) do |verb, hash|
37
37
  klass = const_get verb
38
38
  hash[verb] = klass
39
39
  hash[verb.downcase] = klass
40
40
  hash[verb.downcase.to_sym] = klass
41
41
  end
42
-
43
42
  end
44
43
 
45
44
  def self.verb_matcher(verb)
@@ -74,6 +73,14 @@ module ActionDispatch
74
73
  @internal = internal
75
74
  end
76
75
 
76
+ def eager_load!
77
+ path.eager_load!
78
+ ast
79
+ parts
80
+ required_defaults
81
+ nil
82
+ end
83
+
77
84
  def ast
78
85
  @decorated_ast ||= begin
79
86
  decorated_ast = path.ast
@@ -84,7 +91,7 @@ module ActionDispatch
84
91
 
85
92
  def requirements
86
93
  # needed for rails `rails routes`
87
- @defaults.merge(path.requirements).delete_if { |_,v|
94
+ @defaults.merge(path.requirements).delete_if { |_, v|
88
95
  /.+?/ == v
89
96
  }
90
97
  end
@@ -130,7 +137,7 @@ module ActionDispatch
130
137
  end
131
138
 
132
139
  def required_defaults
133
- @required_defaults ||= @defaults.dup.delete_if do |k,_|
140
+ @required_defaults ||= @defaults.dup.delete_if do |k, _|
134
141
  parts.include?(k) || !required_default?(k)
135
142
  end
136
143
  end
@@ -170,17 +177,17 @@ module ActionDispatch
170
177
  end
171
178
 
172
179
  def verb
173
- verbs.join('|')
180
+ verbs.join("|")
174
181
  end
175
182
 
176
183
  private
177
- def verbs
178
- @request_method_match.map(&:verb)
179
- end
184
+ def verbs
185
+ @request_method_match.map(&:verb)
186
+ end
180
187
 
181
- def match_verb(request)
182
- @request_method_match.any? { |m| m.call request }
183
- end
188
+ def match_verb(request)
189
+ @request_method_match.any? { |m| m.call request }
190
+ end
184
191
  end
185
192
  end
186
193
  # :startdoc:
@@ -1,14 +1,14 @@
1
- require 'action_dispatch/journey/router/utils'
2
- require 'action_dispatch/journey/routes'
3
- require 'action_dispatch/journey/formatter'
1
+ require "action_dispatch/journey/router/utils"
2
+ require "action_dispatch/journey/routes"
3
+ require "action_dispatch/journey/formatter"
4
4
 
5
5
  before = $-w
6
6
  $-w = false
7
- require 'action_dispatch/journey/parser'
7
+ require "action_dispatch/journey/parser"
8
8
  $-w = before
9
9
 
10
- require 'action_dispatch/journey/route'
11
- require 'action_dispatch/journey/path/pattern'
10
+ require "action_dispatch/journey/route"
11
+ require "action_dispatch/journey/path/pattern"
12
12
 
13
13
  module ActionDispatch
14
14
  module Journey # :nodoc:
@@ -22,6 +22,13 @@ module ActionDispatch
22
22
  @routes = routes
23
23
  end
24
24
 
25
+ def eager_load!
26
+ # Eagerly trigger the simulator's initialization so
27
+ # it doesn't happen during a request cycle.
28
+ simulator
29
+ nil
30
+ end
31
+
25
32
  def serve(req)
26
33
  find_routes(req).each do |match, parameters, route|
27
34
  set_params = req.path_parameters
@@ -29,7 +36,7 @@ module ActionDispatch
29
36
  script_name = req.script_name
30
37
 
31
38
  unless route.path.anchored
32
- req.script_name = (script_name.to_s + match.to_s).chomp('/')
39
+ req.script_name = (script_name.to_s + match.to_s).chomp("/")
33
40
  req.path_info = match.post_match
34
41
  req.path_info = "/" + req.path_info unless req.path_info.start_with? "/"
35
42
  end
@@ -38,7 +45,7 @@ module ActionDispatch
38
45
 
39
46
  status, headers, body = route.app.serve(req)
40
47
 
41
- if 'pass' == headers['X-Cascade']
48
+ if "pass" == headers["X-Cascade"]
42
49
  req.script_name = script_name
43
50
  req.path_info = path_info
44
51
  req.path_parameters = set_params
@@ -48,7 +55,7 @@ module ActionDispatch
48
55
  return [status, headers, body]
49
56
  end
50
57
 
51
- return [404, {'X-Cascade' => 'pass'}, ['Not Found']]
58
+ return [404, { "X-Cascade" => "pass" }, ["Not Found"]]
52
59
  end
53
60
 
54
61
  def recognize(rails_req)
@@ -94,7 +101,7 @@ module ActionDispatch
94
101
  simulator.memos(path) { [] }
95
102
  end
96
103
 
97
- def find_routes req
104
+ def find_routes(req)
98
105
  routes = filter_routes(req.path_info).concat custom_routes.find_all { |r|
99
106
  r.path.match(req.path_info)
100
107
  }
@@ -109,9 +116,9 @@ module ActionDispatch
109
116
  routes.sort_by!(&:precedence)
110
117
 
111
118
  routes.map! { |r|
112
- match_data = r.path.match(req.path_info)
119
+ match_data = r.path.match(req.path_info)
113
120
  path_parameters = r.defaults.dup
114
- match_data.names.zip(match_data.captures) { |name,val|
121
+ match_data.names.zip(match_data.captures) { |name, val|
115
122
  path_parameters[name.to_sym] = Utils.unescape_uri(val) if val
116
123
  }
117
124
  [match_data, path_parameters, r]
@@ -14,10 +14,10 @@ module ActionDispatch
14
14
  # normalize_path("/%ab") # => "/%AB"
15
15
  def self.normalize_path(path)
16
16
  path = "/#{path}"
17
- path.squeeze!('/'.freeze)
18
- path.sub!(%r{/+\Z}, ''.freeze)
17
+ path.squeeze!("/".freeze)
18
+ path.sub!(%r{/+\Z}, "".freeze)
19
19
  path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase }
20
- path = '/' if path == ''.freeze
20
+ path = "/" if path == "".freeze
21
21
  path
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ module ActionDispatch
28
28
  US_ASCII = Encoding::US_ASCII
29
29
  UTF_8 = Encoding::UTF_8
30
30
  EMPTY = "".force_encoding(US_ASCII).freeze
31
- DEC2HEX = (0..255).to_a.map{ |i| ENCODE % i }.map{ |s| s.force_encoding(US_ASCII) }
31
+ DEC2HEX = (0..255).to_a.map { |i| ENCODE % i }.map { |s| s.force_encoding(US_ASCII) }
32
32
 
33
33
  ALPHA = "a-zA-Z".freeze
34
34
  DIGIT = "0-9".freeze
@@ -55,15 +55,15 @@ module ActionDispatch
55
55
 
56
56
  def unescape_uri(uri)
57
57
  encoding = uri.encoding == US_ASCII ? UTF_8 : uri.encoding
58
- uri.gsub(ESCAPED) { |match| [match[1, 2].hex].pack('C') }.force_encoding(encoding)
58
+ uri.gsub(ESCAPED) { |match| [match[1, 2].hex].pack("C") }.force_encoding(encoding)
59
59
  end
60
60
 
61
- protected
62
- def escape(component, pattern)
63
- component.gsub(pattern){ |unsafe| percent_encode(unsafe) }.force_encoding(US_ASCII)
61
+ private
62
+ def escape(component, pattern) # :doc:
63
+ component.gsub(pattern) { |unsafe| percent_encode(unsafe) }.force_encoding(US_ASCII)
64
64
  end
65
65
 
66
- def percent_encode(unsafe)
66
+ def percent_encode(unsafe) # :doc:
67
67
  safe = EMPTY.dup
68
68
  unsafe.each_byte { |b| safe << DEC2HEX[b] }
69
69
  safe
@@ -1,4 +1,5 @@
1
- require 'strscan'
1
+ # frozen_string_literal: true
2
+ require "strscan"
2
3
 
3
4
  module ActionDispatch
4
5
  module Journey # :nodoc:
@@ -35,22 +36,23 @@ module ActionDispatch
35
36
  def scan
36
37
  case
37
38
  # /
38
- when text = @ss.scan(/\//)
39
- [:SLASH, text]
39
+ when @ss.skip(/\//)
40
+ [:SLASH, "/"]
41
+ when @ss.skip(/\(/)
42
+ [:LPAREN, "("]
43
+ when @ss.skip(/\)/)
44
+ [:RPAREN, ")"]
45
+ when @ss.skip(/\|/)
46
+ [:OR, "|"]
47
+ when @ss.skip(/\./)
48
+ [:DOT, "."]
49
+ when text = @ss.scan(/:\w+/)
50
+ [:SYMBOL, text]
40
51
  when text = @ss.scan(/\*\w+/)
41
52
  [:STAR, text]
42
- when text = @ss.scan(/(?<!\\)\(/)
43
- [:LPAREN, text]
44
- when text = @ss.scan(/(?<!\\)\)/)
45
- [:RPAREN, text]
46
- when text = @ss.scan(/\|/)
47
- [:OR, text]
48
- when text = @ss.scan(/\./)
49
- [:DOT, text]
50
- when text = @ss.scan(/(?<!\\):\w+/)
51
- [:SYMBOL, text]
52
- when text = @ss.scan(/(?:[\w%\-~!$&'*+,;=@]|\\:|\\\(|\\\))+/)
53
- [:LITERAL, text.tr('\\', '')]
53
+ when text = @ss.scan(/(?:[\w%\-~!$&'*+,;=@]|\\[:()])+/)
54
+ text.tr! "\\", ""
55
+ [:LITERAL, text]
54
56
  # any char
55
57
  when text = @ss.scan(/./)
56
58
  [:LITERAL, text]