actionpack 4.2.11.1 → 6.1.3.2

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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +291 -489
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +9 -9
  5. data/lib/abstract_controller/asset_paths.rb +2 -0
  6. data/lib/abstract_controller/base.rb +81 -51
  7. data/lib/{action_controller → abstract_controller}/caching/fragments.rb +64 -17
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/callbacks.rb +61 -33
  10. data/lib/abstract_controller/collector.rb +9 -13
  11. data/lib/abstract_controller/error.rb +6 -0
  12. data/lib/abstract_controller/helpers.rb +115 -99
  13. data/lib/abstract_controller/logger.rb +2 -0
  14. data/lib/abstract_controller/railties/routes_helpers.rb +21 -3
  15. data/lib/abstract_controller/rendering.rb +48 -47
  16. data/lib/abstract_controller/translation.rb +17 -8
  17. data/lib/abstract_controller/url_for.rb +2 -0
  18. data/lib/abstract_controller.rb +13 -5
  19. data/lib/action_controller/api/api_rendering.rb +16 -0
  20. data/lib/action_controller/api.rb +150 -0
  21. data/lib/action_controller/base.rb +29 -24
  22. data/lib/action_controller/caching.rb +12 -57
  23. data/lib/action_controller/form_builder.rb +50 -0
  24. data/lib/action_controller/log_subscriber.rb +17 -19
  25. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  26. data/lib/action_controller/metal/conditional_get.rb +134 -46
  27. data/lib/action_controller/metal/content_security_policy.rb +51 -0
  28. data/lib/action_controller/metal/cookies.rb +6 -4
  29. data/lib/action_controller/metal/data_streaming.rb +30 -50
  30. data/lib/action_controller/metal/default_headers.rb +17 -0
  31. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  32. data/lib/action_controller/metal/etag_with_template_digest.rb +21 -16
  33. data/lib/action_controller/metal/exceptions.rb +63 -15
  34. data/lib/action_controller/metal/flash.rb +9 -8
  35. data/lib/action_controller/metal/head.rb +26 -21
  36. data/lib/action_controller/metal/helpers.rb +37 -18
  37. data/lib/action_controller/metal/http_authentication.rb +81 -73
  38. data/lib/action_controller/metal/implicit_render.rb +53 -9
  39. data/lib/action_controller/metal/instrumentation.rb +32 -35
  40. data/lib/action_controller/metal/live.rb +102 -120
  41. data/lib/action_controller/metal/logging.rb +20 -0
  42. data/lib/action_controller/metal/mime_responds.rb +49 -47
  43. data/lib/action_controller/metal/parameter_encoding.rb +82 -0
  44. data/lib/action_controller/metal/params_wrapper.rb +83 -66
  45. data/lib/action_controller/metal/permissions_policy.rb +46 -0
  46. data/lib/action_controller/metal/redirecting.rb +53 -32
  47. data/lib/action_controller/metal/renderers.rb +87 -44
  48. data/lib/action_controller/metal/rendering.rb +77 -50
  49. data/lib/action_controller/metal/request_forgery_protection.rb +267 -103
  50. data/lib/action_controller/metal/rescue.rb +10 -17
  51. data/lib/action_controller/metal/streaming.rb +12 -11
  52. data/lib/action_controller/metal/strong_parameters.rb +714 -186
  53. data/lib/action_controller/metal/testing.rb +2 -17
  54. data/lib/action_controller/metal/url_for.rb +19 -10
  55. data/lib/action_controller/metal.rb +104 -87
  56. data/lib/action_controller/railtie.rb +28 -10
  57. data/lib/action_controller/railties/helpers.rb +3 -1
  58. data/lib/action_controller/renderer.rb +141 -0
  59. data/lib/action_controller/template_assertions.rb +11 -0
  60. data/lib/action_controller/test_case.rb +296 -422
  61. data/lib/action_controller.rb +34 -23
  62. data/lib/action_dispatch/http/cache.rb +107 -56
  63. data/lib/action_dispatch/http/content_disposition.rb +45 -0
  64. data/lib/action_dispatch/http/content_security_policy.rb +286 -0
  65. data/lib/action_dispatch/http/filter_parameters.rb +32 -25
  66. data/lib/action_dispatch/http/filter_redirect.rb +10 -12
  67. data/lib/action_dispatch/http/headers.rb +55 -22
  68. data/lib/action_dispatch/http/mime_negotiation.rb +79 -51
  69. data/lib/action_dispatch/http/mime_type.rb +153 -121
  70. data/lib/action_dispatch/http/mime_types.rb +20 -6
  71. data/lib/action_dispatch/http/parameters.rb +90 -40
  72. data/lib/action_dispatch/http/permissions_policy.rb +173 -0
  73. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  74. data/lib/action_dispatch/http/request.rb +226 -121
  75. data/lib/action_dispatch/http/response.rb +248 -113
  76. data/lib/action_dispatch/http/upload.rb +21 -7
  77. data/lib/action_dispatch/http/url.rb +182 -100
  78. data/lib/action_dispatch/journey/formatter.rb +90 -43
  79. data/lib/action_dispatch/journey/gtg/builder.rb +28 -41
  80. data/lib/action_dispatch/journey/gtg/simulator.rb +11 -16
  81. data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -21
  82. data/lib/action_dispatch/journey/nfa/dot.rb +3 -14
  83. data/lib/action_dispatch/journey/nodes/node.rb +29 -15
  84. data/lib/action_dispatch/journey/parser.rb +17 -16
  85. data/lib/action_dispatch/journey/parser.y +4 -3
  86. data/lib/action_dispatch/journey/parser_extras.rb +12 -4
  87. data/lib/action_dispatch/journey/path/pattern.rb +58 -54
  88. data/lib/action_dispatch/journey/route.rb +100 -32
  89. data/lib/action_dispatch/journey/router/utils.rb +29 -18
  90. data/lib/action_dispatch/journey/router.rb +55 -51
  91. data/lib/action_dispatch/journey/routes.rb +17 -17
  92. data/lib/action_dispatch/journey/scanner.rb +26 -17
  93. data/lib/action_dispatch/journey/visitors.rb +98 -54
  94. data/lib/action_dispatch/journey.rb +5 -5
  95. data/lib/action_dispatch/middleware/actionable_exceptions.rb +46 -0
  96. data/lib/action_dispatch/middleware/callbacks.rb +3 -6
  97. data/lib/action_dispatch/middleware/cookies.rb +347 -217
  98. data/lib/action_dispatch/middleware/debug_exceptions.rb +135 -63
  99. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  100. data/lib/action_dispatch/middleware/debug_view.rb +66 -0
  101. data/lib/action_dispatch/middleware/exception_wrapper.rb +115 -71
  102. data/lib/action_dispatch/middleware/executor.rb +21 -0
  103. data/lib/action_dispatch/middleware/flash.rb +78 -54
  104. data/lib/action_dispatch/middleware/host_authorization.rb +130 -0
  105. data/lib/action_dispatch/middleware/public_exceptions.rb +32 -27
  106. data/lib/action_dispatch/middleware/reloader.rb +5 -91
  107. data/lib/action_dispatch/middleware/remote_ip.rb +53 -45
  108. data/lib/action_dispatch/middleware/request_id.rb +17 -10
  109. data/lib/action_dispatch/middleware/session/abstract_store.rb +41 -26
  110. data/lib/action_dispatch/middleware/session/cache_store.rb +24 -14
  111. data/lib/action_dispatch/middleware/session/cookie_store.rb +74 -75
  112. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -2
  113. data/lib/action_dispatch/middleware/show_exceptions.rb +28 -23
  114. data/lib/action_dispatch/middleware/ssl.rb +118 -35
  115. data/lib/action_dispatch/middleware/stack.rb +82 -41
  116. data/lib/action_dispatch/middleware/static.rb +156 -89
  117. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +22 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +4 -14
  121. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
  122. data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +4 -2
  123. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  124. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +45 -35
  125. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +7 -0
  126. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +5 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +23 -4
  128. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +1 -1
  129. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +24 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +15 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +105 -8
  132. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +19 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +2 -2
  135. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -1
  136. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +3 -3
  137. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
  138. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
  139. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
  140. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +87 -64
  141. data/lib/action_dispatch/railtie.rb +27 -13
  142. data/lib/action_dispatch/request/session.rb +109 -61
  143. data/lib/action_dispatch/request/utils.rb +90 -23
  144. data/lib/action_dispatch/routing/endpoint.rb +9 -2
  145. data/lib/action_dispatch/routing/inspector.rb +141 -102
  146. data/lib/action_dispatch/routing/mapper.rb +811 -473
  147. data/lib/action_dispatch/routing/polymorphic_routes.rb +167 -143
  148. data/lib/action_dispatch/routing/redirection.rb +37 -27
  149. data/lib/action_dispatch/routing/route_set.rb +363 -331
  150. data/lib/action_dispatch/routing/routes_proxy.rb +32 -5
  151. data/lib/action_dispatch/routing/url_for.rb +66 -26
  152. data/lib/action_dispatch/routing.rb +36 -36
  153. data/lib/action_dispatch/system_test_case.rb +190 -0
  154. data/lib/action_dispatch/system_testing/browser.rb +86 -0
  155. data/lib/action_dispatch/system_testing/driver.rb +67 -0
  156. data/lib/action_dispatch/system_testing/server.rb +31 -0
  157. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +138 -0
  158. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +29 -0
  159. data/lib/action_dispatch/testing/assertion_response.rb +46 -0
  160. data/lib/action_dispatch/testing/assertions/response.rb +44 -22
  161. data/lib/action_dispatch/testing/assertions/routing.rb +47 -31
  162. data/lib/action_dispatch/testing/assertions.rb +6 -4
  163. data/lib/action_dispatch/testing/integration.rb +391 -220
  164. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  165. data/lib/action_dispatch/testing/test_process.rb +53 -22
  166. data/lib/action_dispatch/testing/test_request.rb +27 -34
  167. data/lib/action_dispatch/testing/test_response.rb +11 -11
  168. data/lib/action_dispatch.rb +35 -21
  169. data/lib/action_pack/gem_version.rb +6 -4
  170. data/lib/action_pack/version.rb +3 -1
  171. data/lib/action_pack.rb +4 -2
  172. metadata +78 -48
  173. data/lib/action_controller/metal/force_ssl.rb +0 -97
  174. data/lib/action_controller/metal/hide_actions.rb +0 -40
  175. data/lib/action_controller/metal/rack_delegation.rb +0 -32
  176. data/lib/action_controller/middleware.rb +0 -39
  177. data/lib/action_controller/model_naming.rb +0 -12
  178. data/lib/action_dispatch/http/parameter_filter.rb +0 -72
  179. data/lib/action_dispatch/journey/backwards.rb +0 -5
  180. data/lib/action_dispatch/journey/nfa/builder.rb +0 -76
  181. data/lib/action_dispatch/journey/nfa/simulator.rb +0 -47
  182. data/lib/action_dispatch/journey/nfa/transition_table.rb +0 -163
  183. data/lib/action_dispatch/journey/router/strexp.rb +0 -27
  184. data/lib/action_dispatch/middleware/params_parser.rb +0 -60
  185. data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
  186. data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
  187. data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
@@ -1,4 +1,6 @@
1
- require 'action_dispatch/journey/gtg/transition_table'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/gtg/transition_table"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -11,45 +13,44 @@ module ActionDispatch
11
13
  def initialize(root)
12
14
  @root = root
13
15
  @ast = Nodes::Cat.new root, DUMMY
14
- @followpos = nil
16
+ @followpos = build_followpos
15
17
  end
16
18
 
17
19
  def transition_table
18
20
  dtrans = TransitionTable.new
19
- marked = {}
20
- state_id = Hash.new { |h,k| h[k] = h.length }
21
+ marked = {}.compare_by_identity
22
+ state_id = Hash.new { |h, k| h[k] = h.length }.compare_by_identity
23
+ dstates = [firstpos(root)]
21
24
 
22
- start = firstpos(root)
23
- dstates = [start]
24
25
  until dstates.empty?
25
26
  s = dstates.shift
26
27
  next if marked[s]
27
28
  marked[s] = true # mark s
28
29
 
29
30
  s.group_by { |state| symbol(state) }.each do |sym, ps|
30
- u = ps.flat_map { |l| followpos(l) }
31
+ u = ps.flat_map { |l| @followpos[l] }
31
32
  next if u.empty?
32
33
 
33
- if u.uniq == [DUMMY]
34
- from = state_id[s]
35
- to = state_id[Object.new]
36
- dtrans[from, to] = sym
34
+ from = state_id[s]
37
35
 
36
+ if u.all? { |pos| pos == DUMMY }
37
+ to = state_id[Object.new]
38
+ dtrans[from, to] = sym
38
39
  dtrans.add_accepting(to)
40
+
39
41
  ps.each { |state| dtrans.add_memo(to, state.memo) }
40
42
  else
41
- dtrans[state_id[s], state_id[u]] = sym
43
+ to = state_id[u]
44
+ dtrans[from, to] = sym
42
45
 
43
46
  if u.include?(DUMMY)
44
- to = state_id[u]
45
-
46
- accepting = ps.find_all { |l| followpos(l).include?(DUMMY) }
47
-
48
- accepting.each { |accepting_state|
49
- dtrans.add_memo(to, accepting_state.memo)
50
- }
47
+ ps.each do |state|
48
+ if @followpos[state].include?(DUMMY)
49
+ dtrans.add_memo(to, state.memo)
50
+ end
51
+ end
51
52
 
52
- dtrans.add_accepting(state_id[u])
53
+ dtrans.add_accepting(to)
53
54
  end
54
55
  end
55
56
 
@@ -75,7 +76,7 @@ module ActionDispatch
75
76
  when Nodes::Unary
76
77
  nullable?(node.left)
77
78
  else
78
- raise ArgumentError, 'unknown nullable: %s' % node.class.name
79
+ raise ArgumentError, "unknown nullable: %s" % node.class.name
79
80
  end
80
81
  end
81
82
 
@@ -90,13 +91,13 @@ module ActionDispatch
90
91
  firstpos(node.left)
91
92
  end
92
93
  when Nodes::Or
93
- node.children.flat_map { |c| firstpos(c) }.uniq
94
+ node.children.flat_map { |c| firstpos(c) }.tap(&:uniq!)
94
95
  when Nodes::Unary
95
96
  firstpos(node.left)
96
97
  when Nodes::Terminal
97
98
  nullable?(node) ? [] : [node]
98
99
  else
99
- raise ArgumentError, 'unknown firstpos: %s' % node.class.name
100
+ raise ArgumentError, "unknown firstpos: %s" % node.class.name
100
101
  end
101
102
  end
102
103
 
@@ -105,7 +106,7 @@ module ActionDispatch
105
106
  when Nodes::Star
106
107
  firstpos(node.left)
107
108
  when Nodes::Or
108
- node.children.flat_map { |c| lastpos(c) }.uniq
109
+ node.children.flat_map { |c| lastpos(c) }.tap(&:uniq!)
109
110
  when Nodes::Cat
110
111
  if nullable?(node.right)
111
112
  lastpos(node.left) | lastpos(node.right)
@@ -117,22 +118,13 @@ module ActionDispatch
117
118
  when Nodes::Unary
118
119
  lastpos(node.left)
119
120
  else
120
- raise ArgumentError, 'unknown lastpos: %s' % node.class.name
121
+ raise ArgumentError, "unknown lastpos: %s" % node.class.name
121
122
  end
122
123
  end
123
124
 
124
- def followpos(node)
125
- followpos_table[node]
126
- end
127
-
128
125
  private
129
-
130
- def followpos_table
131
- @followpos ||= build_followpos
132
- end
133
-
134
126
  def build_followpos
135
- table = Hash.new { |h, k| h[k] = [] }
127
+ table = Hash.new { |h, k| h[k] = [] }.compare_by_identity
136
128
  @ast.each do |n|
137
129
  case n
138
130
  when Nodes::Cat
@@ -149,12 +141,7 @@ module ActionDispatch
149
141
  end
150
142
 
151
143
  def symbol(edge)
152
- case edge
153
- when Journey::Nodes::Symbol
154
- edge.regexp
155
- else
156
- edge.left
157
- end
144
+ edge.symbol? ? edge.regexp : edge.left
158
145
  end
159
146
  end
160
147
  end
@@ -1,4 +1,6 @@
1
- require 'strscan'
1
+ # frozen_string_literal: true
2
+
3
+ require "strscan"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -12,34 +14,27 @@ module ActionDispatch
12
14
  end
13
15
 
14
16
  class Simulator # :nodoc:
17
+ INITIAL_STATE = [0].freeze
18
+
15
19
  attr_reader :tt
16
20
 
17
21
  def initialize(transition_table)
18
22
  @tt = transition_table
19
23
  end
20
24
 
21
- def simulate(string)
22
- ms = memos(string) { return }
23
- MatchData.new(ms)
24
- end
25
-
26
- alias :=~ :simulate
27
- alias :match :simulate
28
-
29
25
  def memos(string)
30
26
  input = StringScanner.new(string)
31
- state = [0]
27
+ state = INITIAL_STATE
28
+
32
29
  while sym = input.scan(%r([/.?]|[^/.?]+))
33
30
  state = tt.move(state, sym)
34
31
  end
35
32
 
36
- acceptance_states = state.find_all { |s|
37
- tt.accepting? s
38
- }
39
-
40
- return yield if acceptance_states.empty?
33
+ acceptance_states = state.each_with_object([]) do |s, memos|
34
+ memos.concat(tt.memo(s)) if tt.accepting?(s)
35
+ end
41
36
 
42
- acceptance_states.flat_map { |x| tt.memo(x) }.compact
37
+ acceptance_states.empty? ? yield : acceptance_states
43
38
  end
44
39
  end
45
40
  end
@@ -1,4 +1,6 @@
1
- require 'action_dispatch/journey/nfa/dot'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/nfa/dot"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -12,7 +14,7 @@ module ActionDispatch
12
14
  @regexp_states = {}
13
15
  @string_states = {}
14
16
  @accepting = {}
15
- @memos = Hash.new { |h,k| h[k] = [] }
17
+ @memos = Hash.new { |h, k| h[k] = [] }
16
18
  end
17
19
 
18
20
  def add_accepting(state)
@@ -43,20 +45,22 @@ module ActionDispatch
43
45
  return [] if t.empty?
44
46
 
45
47
  regexps = []
48
+ strings = []
46
49
 
47
- t.map { |s|
50
+ t.each { |s|
48
51
  if states = @regexp_states[s]
49
- regexps.concat states.map { |re, v| re === a ? v : nil }
52
+ states.each { |re, v| regexps << v if re.match?(a) && !v.nil? }
50
53
  end
51
54
 
52
55
  if states = @string_states[s]
53
- states[a]
56
+ strings << states[a] unless states[a].nil?
54
57
  end
55
- }.compact.concat regexps
58
+ }
59
+ strings.concat regexps
56
60
  end
57
61
 
58
62
  def as_json(options = nil)
59
- simple_regexp = Hash.new { |h,k| h[k] = {} }
63
+ simple_regexp = Hash.new { |h, k| h[k] = {} }
60
64
 
61
65
  @regexp_states.each do |from, hash|
62
66
  hash.each do |re, to|
@@ -72,20 +76,20 @@ module ActionDispatch
72
76
  end
73
77
 
74
78
  def to_svg
75
- svg = IO.popen('dot -Tsvg', 'w+') { |f|
79
+ svg = IO.popen("dot -Tsvg", "w+") { |f|
76
80
  f.write(to_dot)
77
81
  f.close_write
78
82
  f.readlines
79
83
  }
80
84
  3.times { svg.shift }
81
- svg.join.sub(/width="[^"]*"/, '').sub(/height="[^"]*"/, '')
85
+ svg.join.sub(/width="[^"]*"/, "").sub(/height="[^"]*"/, "")
82
86
  end
83
87
 
84
- def visualizer(paths, title = 'FSM')
85
- viz_dir = File.join File.dirname(__FILE__), '..', 'visualizer'
86
- fsm_js = File.read File.join(viz_dir, 'fsm.js')
87
- fsm_css = File.read File.join(viz_dir, 'fsm.css')
88
- erb = File.read File.join(viz_dir, 'index.html.erb')
88
+ def visualizer(paths, title = "FSM")
89
+ viz_dir = File.join __dir__, "..", "visualizer"
90
+ fsm_js = File.read File.join(viz_dir, "fsm.js")
91
+ fsm_css = File.read File.join(viz_dir, "fsm.css")
92
+ erb = File.read File.join(viz_dir, "index.html.erb")
89
93
  states = "function tt() { return #{to_json}; }"
90
94
 
91
95
  fun_routes = paths.sample(3).map do |ast|
@@ -93,10 +97,10 @@ module ActionDispatch
93
97
  case n
94
98
  when Nodes::Symbol
95
99
  case n.left
96
- when ':id' then rand(100).to_s
97
- when ':format' then %w{ xml json }.sample
100
+ when ":id" then rand(100).to_s
101
+ when ":format" then %w{ xml json }.sample
98
102
  else
99
- 'omg'
103
+ "omg"
100
104
  end
101
105
  when Nodes::Terminal then n.symbol
102
106
  else
@@ -109,13 +113,12 @@ module ActionDispatch
109
113
  svg = to_svg
110
114
  javascripts = [states, fsm_js]
111
115
 
112
- # Annoying hack for 1.9 warnings
113
116
  fun_routes = fun_routes
114
117
  stylesheets = stylesheets
115
118
  svg = svg
116
119
  javascripts = javascripts
117
120
 
118
- require 'erb'
121
+ require "erb"
119
122
  template = ERB.new erb
120
123
  template.result(binding)
121
124
  end
@@ -140,7 +143,6 @@ module ActionDispatch
140
143
  end
141
144
 
142
145
  private
143
-
144
146
  def states_hash_for(sym)
145
147
  case sym
146
148
  when String
@@ -148,7 +150,7 @@ module ActionDispatch
148
150
  when Regexp
149
151
  @regexp_states
150
152
  else
151
- raise ArgumentError, 'unknown symbol: %s' % sym.class
153
+ raise ArgumentError, "unknown symbol: %s" % sym.class
152
154
  end
153
155
  end
154
156
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ActionDispatch
4
4
  module Journey # :nodoc:
@@ -9,18 +9,7 @@ module ActionDispatch
9
9
  " #{from} -> #{to} [label=\"#{sym || 'ε'}\"];"
10
10
  }
11
11
 
12
- #memo_nodes = memos.values.flatten.map { |n|
13
- # label = n
14
- # if Journey::Route === n
15
- # label = "#{n.verb.source} #{n.path.spec}"
16
- # end
17
- # " #{n.object_id} [label=\"#{label}\", shape=box];"
18
- #}
19
- #memo_edges = memos.flat_map { |k, memos|
20
- # (memos || []).map { |v| " #{k} -> #{v.object_id};" }
21
- #}.uniq
22
-
23
- <<-eodot
12
+ <<-eodot
24
13
  digraph nfa {
25
14
  rankdir=LR;
26
15
  node [shape = doublecircle];
@@ -28,7 +17,7 @@ digraph nfa {
28
17
  node [shape = circle];
29
18
  #{edges.join "\n"}
30
19
  }
31
- eodot
20
+ eodot
32
21
  end
33
22
  end
34
23
  end
@@ -1,4 +1,6 @@
1
- require 'action_dispatch/journey/visitors'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/visitors"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -14,15 +16,15 @@ module ActionDispatch
14
16
  end
15
17
 
16
18
  def each(&block)
17
- Visitors::Each.new(block).accept(self)
19
+ Visitors::Each::INSTANCE.accept(self, block)
18
20
  end
19
21
 
20
22
  def to_s
21
- Visitors::String.new.accept(self)
23
+ Visitors::String::INSTANCE.accept(self, "")
22
24
  end
23
25
 
24
26
  def to_dot
25
- Visitors::Dot.new.accept(self)
27
+ Visitors::Dot::INSTANCE.accept(self)
26
28
  end
27
29
 
28
30
  def to_sym
@@ -30,7 +32,7 @@ module ActionDispatch
30
32
  end
31
33
 
32
34
  def name
33
- left.tr '*:', ''
35
+ -left.tr("*:", "")
34
36
  end
35
37
 
36
38
  def type
@@ -39,10 +41,15 @@ module ActionDispatch
39
41
 
40
42
  def symbol?; false; end
41
43
  def literal?; false; end
44
+ def terminal?; false; end
45
+ def star?; false; end
46
+ def cat?; false; end
47
+ def group?; false; end
42
48
  end
43
49
 
44
50
  class Terminal < Node # :nodoc:
45
51
  alias :symbol :left
52
+ def terminal?; true; end
46
53
  end
47
54
 
48
55
  class Literal < Terminal # :nodoc:
@@ -58,28 +65,32 @@ module ActionDispatch
58
65
  def literal?; false; end
59
66
  end
60
67
 
61
- %w{ Symbol Slash Dot }.each do |t|
62
- class_eval <<-eoruby, __FILE__, __LINE__ + 1
63
- class #{t} < Terminal;
64
- def type; :#{t.upcase}; end
65
- end
66
- eoruby
68
+ class Slash < Terminal # :nodoc:
69
+ def type; :SLASH; end
70
+ end
71
+
72
+ class Dot < Terminal # :nodoc:
73
+ def type; :DOT; end
67
74
  end
68
75
 
69
76
  class Symbol < Terminal # :nodoc:
70
77
  attr_accessor :regexp
71
78
  alias :symbol :regexp
79
+ attr_reader :name
72
80
 
73
81
  DEFAULT_EXP = /[^\.\/\?]+/
74
- def initialize(left)
75
- super
76
- @regexp = DEFAULT_EXP
82
+ GREEDY_EXP = /(.+)/
83
+ def initialize(left, regexp = DEFAULT_EXP)
84
+ super(left)
85
+ @regexp = regexp
86
+ @name = -left.tr("*:", "")
77
87
  end
78
88
 
79
89
  def default_regexp?
80
90
  regexp == DEFAULT_EXP
81
91
  end
82
92
 
93
+ def type; :SYMBOL; end
83
94
  def symbol?; true; end
84
95
  end
85
96
 
@@ -89,13 +100,15 @@ module ActionDispatch
89
100
 
90
101
  class Group < Unary # :nodoc:
91
102
  def type; :GROUP; end
103
+ def group?; true; end
92
104
  end
93
105
 
94
106
  class Star < Unary # :nodoc:
107
+ def star?; true; end
95
108
  def type; :STAR; end
96
109
 
97
110
  def name
98
- left.name.tr '*:', ''
111
+ left.name.tr "*:", ""
99
112
  end
100
113
  end
101
114
 
@@ -111,6 +124,7 @@ module ActionDispatch
111
124
  end
112
125
 
113
126
  class Cat < Binary # :nodoc:
127
+ def cat?; true; end
114
128
  def type; :CAT; end
115
129
  end
116
130
 
@@ -1,32 +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.16
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
13
  module Journey
13
14
  class Parser < Racc::Parser
14
15
  ##### State transition tables begin ###
15
16
 
16
17
  racc_action_table = [
17
- 13, 15, 14, 7, 21, 16, 8, 19, 13, 15,
18
- 14, 7, 17, 16, 8, 13, 15, 14, 7, 24,
19
- 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 ]
20
21
 
21
22
  racc_action_check = [
22
- 2, 2, 2, 2, 17, 2, 2, 2, 0, 0,
23
- 0, 0, 1, 0, 0, 19, 19, 19, 19, 20,
24
- 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 ]
25
26
 
26
27
  racc_action_pointer = [
27
- 6, 12, -2, nil, nil, nil, nil, 20, nil, nil,
28
- nil, nil, nil, nil, nil, nil, nil, 4, nil, 13,
29
- 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 ]
30
31
 
31
32
  racc_action_default = [
32
33
  -19, -19, -2, -3, -4, -5, -6, -19, -10, -11,
@@ -162,7 +163,7 @@ def _reduce_9(val, _values)
162
163
  end
163
164
 
164
165
  def _reduce_10(val, _values)
165
- Star.new(Symbol.new(val.last))
166
+ Star.new(Symbol.new(val.last, Symbol::GREEDY_EXP))
166
167
  end
167
168
 
168
169
  # reduce 11 omitted
@@ -174,7 +175,7 @@ end
174
175
  # reduce 14 omitted
175
176
 
176
177
  def _reduce_15(val, _values)
177
- Slash.new('/')
178
+ Slash.new(val.first)
178
179
  end
179
180
 
180
181
  def _reduce_16(val, _values)
@@ -194,5 +195,5 @@ def _reduce_none(val, _values)
194
195
  end
195
196
 
196
197
  end # class Parser
197
- end # module Journey
198
- end # module ActionDispatch
198
+ end # module Journey
199
+ end # module ActionDispatch
@@ -21,7 +21,7 @@ rule
21
21
  | expression OR or { Or.new([val.first, val.last]) }
22
22
  ;
23
23
  star
24
- : STAR { Star.new(Symbol.new(val.last)) }
24
+ : STAR { Star.new(Symbol.new(val.last, Symbol::GREEDY_EXP)) }
25
25
  ;
26
26
  terminal
27
27
  : symbol
@@ -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,11 +1,18 @@
1
- require 'action_dispatch/journey/scanner'
2
- require 'action_dispatch/journey/nodes/node'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/scanner"
4
+ require "action_dispatch/journey/nodes/node"
3
5
 
4
6
  module ActionDispatch
5
- module Journey # :nodoc:
6
- class Parser < Racc::Parser # :nodoc:
7
+ # :stopdoc:
8
+ module Journey
9
+ class Parser < Racc::Parser
7
10
  include Journey::Nodes
8
11
 
12
+ def self.parse(string)
13
+ new.parse string
14
+ end
15
+
9
16
  def initialize
10
17
  @scanner = Scanner.new
11
18
  end
@@ -20,4 +27,5 @@ module ActionDispatch
20
27
  end
21
28
  end
22
29
  end
30
+ # :startdoc:
23
31
  end