actionpack 3.2.19 → 4.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +850 -401
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -288
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +39 -37
- data/lib/abstract_controller/callbacks.rb +101 -82
- data/lib/abstract_controller/collector.rb +7 -3
- data/lib/abstract_controller/helpers.rb +25 -13
- data/lib/abstract_controller/layouts.rb +74 -74
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/rendering.rb +30 -13
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +6 -6
- data/lib/abstract_controller/view_paths.rb +1 -1
- data/lib/abstract_controller.rb +1 -8
- data/lib/action_controller/base.rb +46 -22
- data/lib/action_controller/caching/fragments.rb +23 -53
- data/lib/action_controller/caching.rb +46 -33
- data/lib/action_controller/deprecated/integration_test.rb +3 -0
- data/lib/action_controller/deprecated.rb +5 -1
- data/lib/action_controller/log_subscriber.rb +16 -8
- data/lib/action_controller/metal/conditional_get.rb +76 -32
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +24 -9
- data/lib/action_controller/metal/force_ssl.rb +70 -12
- data/lib/action_controller/metal/head.rb +25 -4
- data/lib/action_controller/metal/helpers.rb +5 -9
- data/lib/action_controller/metal/hide_actions.rb +0 -1
- data/lib/action_controller/metal/http_authentication.rb +107 -83
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +2 -1
- data/lib/action_controller/metal/live.rb +175 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -47
- data/lib/action_controller/metal/params_wrapper.rb +112 -74
- data/lib/action_controller/metal/rack_delegation.rb +9 -3
- data/lib/action_controller/metal/redirecting.rb +15 -20
- data/lib/action_controller/metal/renderers.rb +11 -9
- data/lib/action_controller/metal/rendering.rb +9 -1
- data/lib/action_controller/metal/request_forgery_protection.rb +112 -19
- data/lib/action_controller/metal/responder.rb +20 -19
- data/lib/action_controller/metal/streaming.rb +12 -18
- data/lib/action_controller/metal/strong_parameters.rb +520 -0
- data/lib/action_controller/metal/testing.rb +13 -18
- data/lib/action_controller/metal/url_for.rb +28 -25
- data/lib/action_controller/metal.rb +17 -32
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +33 -17
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/record_identifier.rb +18 -72
- data/lib/action_controller/test_case.rb +251 -131
- data/lib/action_controller/vendor/html-scanner.rb +4 -19
- data/lib/action_controller.rb +15 -6
- data/lib/action_dispatch/http/cache.rb +63 -11
- data/lib/action_dispatch/http/filter_parameters.rb +18 -8
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +49 -17
- data/lib/action_dispatch/http/mime_negotiation.rb +24 -1
- data/lib/action_dispatch/http/mime_type.rb +154 -100
- data/lib/action_dispatch/http/mime_types.rb +1 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +28 -28
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +64 -18
- data/lib/action_dispatch/http/response.rb +130 -35
- data/lib/action_dispatch/http/upload.rb +63 -20
- data/lib/action_dispatch/http/url.rb +98 -35
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +146 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +44 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +156 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +124 -0
- data/lib/action_dispatch/journey/parser.rb +206 -0
- data/lib/action_dispatch/journey/parser.y +47 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +196 -0
- data/lib/action_dispatch/journey/route.rb +124 -0
- data/lib/action_dispatch/journey/router/strexp.rb +24 -0
- data/lib/action_dispatch/journey/router/utils.rb +54 -0
- data/lib/action_dispatch/journey/router.rb +166 -0
- data/lib/action_dispatch/journey/routes.rb +75 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +197 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +34 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/middleware/callbacks.rb +9 -4
- data/lib/action_dispatch/middleware/cookies.rb +259 -114
- data/lib/action_dispatch/middleware/debug_exceptions.rb +26 -17
- data/lib/action_dispatch/middleware/exception_wrapper.rb +29 -3
- data/lib/action_dispatch/middleware/flash.rb +58 -58
- data/lib/action_dispatch/middleware/params_parser.rb +14 -29
- data/lib/action_dispatch/middleware/public_exceptions.rb +30 -14
- data/lib/action_dispatch/middleware/reloader.rb +6 -6
- data/lib/action_dispatch/middleware/remote_ip.rb +145 -39
- data/lib/action_dispatch/middleware/request_id.rb +2 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cookie_store.rb +82 -28
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +12 -45
- data/lib/action_dispatch/middleware/ssl.rb +70 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +2 -1
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +14 -11
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +25 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +7 -9
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +15 -9
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +127 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +7 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +30 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +39 -13
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +6 -2
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +144 -0
- data/lib/action_dispatch/railtie.rb +16 -6
- data/lib/action_dispatch/request/session.rb +181 -0
- data/lib/action_dispatch/routing/inspector.rb +240 -0
- data/lib/action_dispatch/routing/mapper.rb +540 -291
- data/lib/action_dispatch/routing/polymorphic_routes.rb +16 -20
- data/lib/action_dispatch/routing/redirection.rb +46 -29
- data/lib/action_dispatch/routing/route_set.rb +207 -164
- data/lib/action_dispatch/routing/routes_proxy.rb +2 -0
- data/lib/action_dispatch/routing/url_for.rb +48 -33
- data/lib/action_dispatch/routing.rb +48 -83
- data/lib/action_dispatch/testing/assertions/dom.rb +3 -13
- data/lib/action_dispatch/testing/assertions/response.rb +32 -40
- data/lib/action_dispatch/testing/assertions/routing.rb +42 -41
- data/lib/action_dispatch/testing/assertions/selector.rb +17 -22
- data/lib/action_dispatch/testing/assertions/tag.rb +20 -23
- data/lib/action_dispatch/testing/integration.rb +65 -51
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +7 -3
- data/lib/action_dispatch.rb +21 -15
- data/lib/action_pack/version.rb +7 -6
- data/lib/action_pack.rb +1 -1
- data/lib/action_view/base.rb +15 -34
- data/lib/action_view/buffers.rb +7 -1
- data/lib/action_view/context.rb +4 -4
- data/lib/action_view/dependency_tracker.rb +93 -0
- data/lib/action_view/digestor.rb +85 -0
- data/lib/action_view/flows.rb +1 -4
- data/lib/action_view/helpers/active_model_helper.rb +3 -4
- data/lib/action_view/helpers/asset_tag_helper.rb +215 -352
- data/lib/action_view/helpers/asset_url_helper.rb +355 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +13 -10
- data/lib/action_view/helpers/cache_helper.rb +150 -18
- data/lib/action_view/helpers/capture_helper.rb +44 -31
- data/lib/action_view/helpers/csrf_helper.rb +0 -2
- data/lib/action_view/helpers/date_helper.rb +269 -248
- data/lib/action_view/helpers/debug_helper.rb +10 -11
- data/lib/action_view/helpers/form_helper.rb +931 -537
- data/lib/action_view/helpers/form_options_helper.rb +341 -166
- data/lib/action_view/helpers/form_tag_helper.rb +190 -90
- data/lib/action_view/helpers/javascript_helper.rb +23 -16
- data/lib/action_view/helpers/number_helper.rb +148 -329
- data/lib/action_view/helpers/output_safety_helper.rb +3 -3
- data/lib/action_view/helpers/record_tag_helper.rb +17 -22
- data/lib/action_view/helpers/rendering_helper.rb +2 -2
- data/lib/action_view/helpers/sanitize_helper.rb +3 -6
- data/lib/action_view/helpers/tag_helper.rb +46 -33
- data/lib/action_view/helpers/tags/base.rb +147 -0
- data/lib/action_view/helpers/tags/check_box.rb +64 -0
- data/lib/action_view/helpers/tags/checkable.rb +16 -0
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +43 -0
- data/lib/action_view/helpers/tags/collection_helpers.rb +83 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +36 -0
- data/lib/action_view/helpers/tags/collection_select.rb +28 -0
- data/lib/action_view/helpers/tags/color_field.rb +25 -0
- data/lib/action_view/helpers/tags/date_field.rb +13 -0
- data/lib/action_view/helpers/tags/date_select.rb +72 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +22 -0
- data/lib/action_view/helpers/tags/datetime_local_field.rb +19 -0
- data/lib/action_view/helpers/tags/datetime_select.rb +8 -0
- data/lib/action_view/helpers/tags/email_field.rb +8 -0
- data/lib/action_view/helpers/tags/file_field.rb +8 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +29 -0
- data/lib/action_view/helpers/tags/hidden_field.rb +8 -0
- data/lib/action_view/helpers/tags/label.rb +65 -0
- data/lib/action_view/helpers/tags/month_field.rb +13 -0
- data/lib/action_view/helpers/tags/number_field.rb +18 -0
- data/lib/action_view/helpers/tags/password_field.rb +12 -0
- data/lib/action_view/helpers/tags/radio_button.rb +31 -0
- data/lib/action_view/helpers/tags/range_field.rb +8 -0
- data/lib/action_view/helpers/tags/search_field.rb +24 -0
- data/lib/action_view/helpers/tags/select.rb +40 -0
- data/lib/action_view/helpers/tags/tel_field.rb +8 -0
- data/lib/action_view/helpers/tags/text_area.rb +18 -0
- data/lib/action_view/helpers/tags/text_field.rb +29 -0
- data/lib/action_view/helpers/tags/time_field.rb +13 -0
- data/lib/action_view/helpers/tags/time_select.rb +8 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +20 -0
- data/lib/action_view/helpers/tags/url_field.rb +8 -0
- data/lib/action_view/helpers/tags/week_field.rb +13 -0
- data/lib/action_view/helpers/tags.rb +39 -0
- data/lib/action_view/helpers/text_helper.rb +130 -114
- data/lib/action_view/helpers/translation_helper.rb +32 -16
- data/lib/action_view/helpers/url_helper.rb +211 -270
- data/lib/action_view/helpers.rb +2 -4
- data/lib/action_view/locale/en.yml +1 -105
- data/lib/action_view/log_subscriber.rb +6 -4
- data/lib/action_view/lookup_context.rb +15 -28
- data/lib/action_view/model_naming.rb +12 -0
- data/lib/action_view/path_set.rb +8 -20
- data/lib/action_view/railtie.rb +6 -22
- data/lib/action_view/record_identifier.rb +84 -0
- data/lib/action_view/renderer/abstract_renderer.rb +25 -19
- data/lib/action_view/renderer/partial_renderer.rb +158 -81
- data/lib/action_view/renderer/renderer.rb +8 -12
- data/lib/action_view/renderer/streaming_template_renderer.rb +2 -5
- data/lib/action_view/renderer/template_renderer.rb +12 -10
- data/lib/action_view/routing_url_for.rb +107 -0
- data/lib/action_view/template/error.rb +22 -12
- data/lib/action_view/template/handlers/builder.rb +1 -1
- data/lib/action_view/template/handlers/erb.rb +40 -19
- data/lib/action_view/template/handlers/raw.rb +11 -0
- data/lib/action_view/template/handlers.rb +12 -9
- data/lib/action_view/template/resolver.rb +107 -53
- data/lib/action_view/template/text.rb +12 -8
- data/lib/action_view/template/types.rb +57 -0
- data/lib/action_view/template.rb +25 -23
- data/lib/action_view/test_case.rb +67 -42
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/document.rb +0 -0
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/node.rb +12 -12
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/sanitizer.rb +13 -2
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/selector.rb +9 -9
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/version.rb +0 -0
- data/lib/action_view/vendor/html-scanner.rb +20 -0
- data/lib/action_view.rb +17 -8
- metadata +184 -214
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
data/lib/action_view/template.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'active_support/core_ext/array/wrap'
|
|
2
|
-
require 'active_support/core_ext/object/blank'
|
|
3
1
|
require 'active_support/core_ext/object/try'
|
|
4
2
|
require 'active_support/core_ext/kernel/singleton_class'
|
|
5
3
|
require 'thread'
|
|
@@ -82,8 +80,7 @@ module ActionView
|
|
|
82
80
|
# problems with converting the user's data to
|
|
83
81
|
# the <tt>default_internal</tt>.
|
|
84
82
|
#
|
|
85
|
-
# To do so, simply raise
|
|
86
|
-
# as follows:
|
|
83
|
+
# To do so, simply raise +WrongEncodingError+ as follows:
|
|
87
84
|
#
|
|
88
85
|
# raise WrongEncodingError.new(
|
|
89
86
|
# problematic_string,
|
|
@@ -94,6 +91,7 @@ module ActionView
|
|
|
94
91
|
autoload :Error
|
|
95
92
|
autoload :Handlers
|
|
96
93
|
autoload :Text
|
|
94
|
+
autoload :Types
|
|
97
95
|
end
|
|
98
96
|
|
|
99
97
|
extend Template::Handlers
|
|
@@ -123,7 +121,7 @@ module ActionView
|
|
|
123
121
|
@locals = details[:locals] || []
|
|
124
122
|
@virtual_path = details[:virtual_path]
|
|
125
123
|
@updated_at = details[:updated_at] || Time.now
|
|
126
|
-
@formats
|
|
124
|
+
@formats = Array(format).map { |f| f.respond_to?(:ref) ? f.ref : f }
|
|
127
125
|
@compile_mutex = Mutex.new
|
|
128
126
|
end
|
|
129
127
|
|
|
@@ -140,7 +138,7 @@ module ActionView
|
|
|
140
138
|
# we use a bang in this instrumentation because you don't want to
|
|
141
139
|
# consume this in production. This is only slow if it's being listened to.
|
|
142
140
|
def render(view, locals, buffer=nil, &block)
|
|
143
|
-
ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path
|
|
141
|
+
ActiveSupport::Notifications.instrument("!render_template.action_view", virtual_path: @virtual_path, identifier: @identifier) do
|
|
144
142
|
compile!(view)
|
|
145
143
|
view.send(method_name, locals, buffer, &block)
|
|
146
144
|
end
|
|
@@ -149,9 +147,15 @@ module ActionView
|
|
|
149
147
|
end
|
|
150
148
|
|
|
151
149
|
def mime_type
|
|
150
|
+
message = 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.'
|
|
151
|
+
ActiveSupport::Deprecation.warn message
|
|
152
152
|
@mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
+
def type
|
|
156
|
+
@type ||= Types[@formats.first] if @formats.first
|
|
157
|
+
end
|
|
158
|
+
|
|
155
159
|
# Receives a view object and return a template similar to self by using @virtual_path.
|
|
156
160
|
#
|
|
157
161
|
# This method is useful if you have a template object but it does not contain its source
|
|
@@ -186,7 +190,7 @@ module ActionView
|
|
|
186
190
|
# before passing the source on to the template engine, leaving a
|
|
187
191
|
# blank line in its stead.
|
|
188
192
|
def encode!
|
|
189
|
-
return unless source.
|
|
193
|
+
return unless source.encoding == Encoding::BINARY
|
|
190
194
|
|
|
191
195
|
# Look for # encoding: *. If we find one, we'll encode the
|
|
192
196
|
# String in that encoding, otherwise, we'll use the
|
|
@@ -277,20 +281,18 @@ module ActionView
|
|
|
277
281
|
end
|
|
278
282
|
end_src
|
|
279
283
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
source.force_encoding(code.encoding)
|
|
284
|
+
# Make sure the source is in the encoding of the returned code
|
|
285
|
+
source.force_encoding(code.encoding)
|
|
283
286
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
# In case we get back a String from a handler that is not in
|
|
288
|
+
# BINARY or the default_internal, encode it to the default_internal
|
|
289
|
+
source.encode!
|
|
287
290
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
end
|
|
291
|
+
# Now, validate that the source we got back from the template
|
|
292
|
+
# handler is valid in the default_internal. This is for handlers
|
|
293
|
+
# that handle encoding but screw up
|
|
294
|
+
unless source.valid_encoding?
|
|
295
|
+
raise WrongEncodingError.new(@source, Encoding.default_internal)
|
|
294
296
|
end
|
|
295
297
|
|
|
296
298
|
begin
|
|
@@ -303,7 +305,7 @@ module ActionView
|
|
|
303
305
|
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
|
|
304
306
|
end
|
|
305
307
|
|
|
306
|
-
raise ActionView::Template::Error.new(self,
|
|
308
|
+
raise ActionView::Template::Error.new(self, e)
|
|
307
309
|
end
|
|
308
310
|
end
|
|
309
311
|
|
|
@@ -312,18 +314,18 @@ module ActionView
|
|
|
312
314
|
e.sub_template_of(self)
|
|
313
315
|
raise e
|
|
314
316
|
else
|
|
315
|
-
assigns = view.respond_to?(:assigns) ? view.assigns : {}
|
|
316
317
|
template = self
|
|
317
318
|
unless template.source
|
|
318
319
|
template = refresh(view)
|
|
319
320
|
template.encode!
|
|
320
321
|
end
|
|
321
|
-
raise Template::Error.new(template,
|
|
322
|
+
raise Template::Error.new(template, e)
|
|
322
323
|
end
|
|
323
324
|
end
|
|
324
325
|
|
|
325
326
|
def locals_code #:nodoc:
|
|
326
|
-
|
|
327
|
+
# Double assign to suppress the dreaded 'assigned but unused variable' warning
|
|
328
|
+
@locals.map { |key| "#{key} = #{key} = local_assigns[:#{key}];" }.join
|
|
327
329
|
end
|
|
328
330
|
|
|
329
331
|
def method_name #:nodoc:
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'active_support/core_ext/object/blank'
|
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
|
3
1
|
require 'active_support/core_ext/module/remove_method'
|
|
4
2
|
require 'action_controller'
|
|
5
3
|
require 'action_controller/test_case'
|
|
@@ -40,10 +38,13 @@ module ActionView
|
|
|
40
38
|
include ActionView::Context
|
|
41
39
|
|
|
42
40
|
include ActionDispatch::Routing::PolymorphicRoutes
|
|
43
|
-
include ActionController::RecordIdentifier
|
|
44
41
|
|
|
45
42
|
include AbstractController::Helpers
|
|
46
43
|
include ActionView::Helpers
|
|
44
|
+
include ActionView::RecordIdentifier
|
|
45
|
+
include ActionView::RoutingUrlFor
|
|
46
|
+
|
|
47
|
+
include ActiveSupport::Testing::ConstantLookup
|
|
47
48
|
|
|
48
49
|
delegate :lookup_context, :to => :controller
|
|
49
50
|
attr_accessor :controller, :output_buffer, :rendered
|
|
@@ -59,10 +60,9 @@ module ActionView
|
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
def determine_default_helper_class(name)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
nil
|
|
63
|
+
determine_constant_from_test_name(name) do |constant|
|
|
64
|
+
Module === constant && !(Class === constant)
|
|
65
|
+
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def helper_method(*methods)
|
|
@@ -116,8 +116,33 @@ module ActionView
|
|
|
116
116
|
output
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
def
|
|
120
|
-
@
|
|
119
|
+
def rendered_views
|
|
120
|
+
@_rendered_views ||= RenderedViewsCollection.new
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class RenderedViewsCollection
|
|
124
|
+
def initialize
|
|
125
|
+
@rendered_views ||= Hash.new { |hash, key| hash[key] = [] }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def add(view, locals)
|
|
129
|
+
@rendered_views[view] ||= []
|
|
130
|
+
@rendered_views[view] << locals
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def locals_for(view)
|
|
134
|
+
@rendered_views[view]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def rendered_views
|
|
138
|
+
@rendered_views.keys
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def view_rendered?(view, expected_locals)
|
|
142
|
+
locals_for(view).any? do |actual_locals|
|
|
143
|
+
expected_locals.all? {|key, value| value == actual_locals[key] }
|
|
144
|
+
end
|
|
145
|
+
end
|
|
121
146
|
end
|
|
122
147
|
|
|
123
148
|
included do
|
|
@@ -153,18 +178,18 @@ module ActionView
|
|
|
153
178
|
end
|
|
154
179
|
|
|
155
180
|
module Locals
|
|
156
|
-
attr_accessor :
|
|
181
|
+
attr_accessor :rendered_views
|
|
157
182
|
|
|
158
183
|
def render(options = {}, local_assigns = {})
|
|
159
184
|
case options
|
|
160
185
|
when Hash
|
|
161
186
|
if block_given?
|
|
162
|
-
|
|
187
|
+
rendered_views.add options[:layout], options[:locals]
|
|
163
188
|
elsif options.key?(:partial)
|
|
164
|
-
|
|
189
|
+
rendered_views.add options[:partial], options[:locals]
|
|
165
190
|
end
|
|
166
191
|
else
|
|
167
|
-
|
|
192
|
+
rendered_views.add options, local_assigns
|
|
168
193
|
end
|
|
169
194
|
|
|
170
195
|
super
|
|
@@ -177,7 +202,7 @@ module ActionView
|
|
|
177
202
|
view = @controller.view_context
|
|
178
203
|
view.singleton_class.send :include, _helpers
|
|
179
204
|
view.extend(Locals)
|
|
180
|
-
view.
|
|
205
|
+
view.rendered_views = self.rendered_views
|
|
181
206
|
view.output_buffer = self.output_buffer
|
|
182
207
|
view
|
|
183
208
|
end
|
|
@@ -185,32 +210,34 @@ module ActionView
|
|
|
185
210
|
|
|
186
211
|
alias_method :_view, :view
|
|
187
212
|
|
|
188
|
-
INTERNAL_IVARS =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
INTERNAL_IVARS = [
|
|
214
|
+
:@__name__,
|
|
215
|
+
:@__io__,
|
|
216
|
+
:@_assertion_wrapped,
|
|
217
|
+
:@_assertions,
|
|
218
|
+
:@_result,
|
|
219
|
+
:@_routes,
|
|
220
|
+
:@controller,
|
|
221
|
+
:@_layouts,
|
|
222
|
+
:@_files,
|
|
223
|
+
:@_rendered_views,
|
|
224
|
+
:@method_name,
|
|
225
|
+
:@output_buffer,
|
|
226
|
+
:@_partials,
|
|
227
|
+
:@passed,
|
|
228
|
+
:@rendered,
|
|
229
|
+
:@request,
|
|
230
|
+
:@routes,
|
|
231
|
+
:@tagged_logger,
|
|
232
|
+
:@_templates,
|
|
233
|
+
:@options,
|
|
234
|
+
:@test_passed,
|
|
235
|
+
:@view,
|
|
236
|
+
:@view_context_class
|
|
237
|
+
]
|
|
211
238
|
|
|
212
239
|
def _user_defined_ivars
|
|
213
|
-
instance_variables
|
|
240
|
+
instance_variables - INTERNAL_IVARS
|
|
214
241
|
end
|
|
215
242
|
|
|
216
243
|
# Returns a Hash of instance variables and their values, as defined by
|
|
@@ -218,8 +245,8 @@ module ActionView
|
|
|
218
245
|
# rendered. This is generally intended for internal use and extension
|
|
219
246
|
# frameworks.
|
|
220
247
|
def view_assigns
|
|
221
|
-
Hash[_user_defined_ivars.map do |
|
|
222
|
-
[
|
|
248
|
+
Hash[_user_defined_ivars.map do |ivar|
|
|
249
|
+
[ivar[1..-1].to_sym, instance_variable_get(ivar)]
|
|
223
250
|
end]
|
|
224
251
|
end
|
|
225
252
|
|
|
@@ -236,10 +263,8 @@ module ActionView
|
|
|
236
263
|
super
|
|
237
264
|
end
|
|
238
265
|
end
|
|
239
|
-
|
|
240
266
|
end
|
|
241
267
|
|
|
242
268
|
include Behavior
|
|
243
|
-
|
|
244
269
|
end
|
|
245
270
|
end
|
|
File without changes
|
|
@@ -383,32 +383,32 @@ module HTML #:nodoc:
|
|
|
383
383
|
# Usage:
|
|
384
384
|
#
|
|
385
385
|
# # test if the node is a "span" tag
|
|
386
|
-
# node.match :
|
|
386
|
+
# node.match tag: "span"
|
|
387
387
|
#
|
|
388
388
|
# # test if the node's parent is a "div"
|
|
389
|
-
# node.match :
|
|
389
|
+
# node.match parent: { tag: "div" }
|
|
390
390
|
#
|
|
391
391
|
# # test if any of the node's ancestors are "table" tags
|
|
392
|
-
# node.match :
|
|
392
|
+
# node.match ancestor: { tag: "table" }
|
|
393
393
|
#
|
|
394
394
|
# # test if any of the node's immediate children are "em" tags
|
|
395
|
-
# node.match :
|
|
395
|
+
# node.match child: { tag: "em" }
|
|
396
396
|
#
|
|
397
397
|
# # test if any of the node's descendants are "strong" tags
|
|
398
|
-
# node.match :
|
|
398
|
+
# node.match descendant: { tag: "strong" }
|
|
399
399
|
#
|
|
400
400
|
# # test if the node has between 2 and 4 span tags as immediate children
|
|
401
|
-
# node.match :
|
|
401
|
+
# node.match children: { count: 2..4, only: { tag: "span" } }
|
|
402
402
|
#
|
|
403
403
|
# # get funky: test to see if the node is a "div", has a "ul" ancestor
|
|
404
404
|
# # and an "li" parent (with "class" = "enum"), and whether or not it has
|
|
405
405
|
# # a "span" descendant that contains # text matching /hello world/:
|
|
406
|
-
# node.match :
|
|
407
|
-
# :
|
|
408
|
-
# :
|
|
409
|
-
# :
|
|
410
|
-
# :
|
|
411
|
-
# :
|
|
406
|
+
# node.match tag: "div",
|
|
407
|
+
# ancestor: { tag: "ul" },
|
|
408
|
+
# parent: { tag: "li",
|
|
409
|
+
# attributes: { class: "enum" } },
|
|
410
|
+
# descendant: { tag: "span",
|
|
411
|
+
# child: /hello world/ }
|
|
412
412
|
def match(conditions)
|
|
413
413
|
conditions = validate_conditions(conditions)
|
|
414
414
|
# check content of child nodes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require 'set'
|
|
2
2
|
require 'cgi'
|
|
3
|
-
require 'active_support/core_ext/class/
|
|
3
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
|
4
4
|
|
|
5
5
|
module HTML
|
|
6
6
|
class Sanitizer
|
|
7
7
|
def sanitize(text, options = {})
|
|
8
|
+
validate_options(options)
|
|
8
9
|
return text unless sanitizeable?(text)
|
|
9
10
|
tokenize(text, options).join
|
|
10
11
|
end
|
|
@@ -27,6 +28,16 @@ module HTML
|
|
|
27
28
|
def process_node(node, result, options)
|
|
28
29
|
result << node.to_s
|
|
29
30
|
end
|
|
31
|
+
|
|
32
|
+
def validate_options(options)
|
|
33
|
+
if options[:tags] && !options[:tags].is_a?(Enumerable)
|
|
34
|
+
raise ArgumentError, "You should pass :tags as an Enumerable"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
if options[:attributes] && !options[:attributes].is_a?(Enumerable)
|
|
38
|
+
raise ArgumentError, "You should pass :attributes as an Enumerable"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
30
41
|
end
|
|
31
42
|
|
|
32
43
|
class FullSanitizer < Sanitizer
|
|
@@ -88,7 +99,7 @@ module HTML
|
|
|
88
99
|
self.allowed_protocols = Set.new(%w(ed2k ftp http https irc mailto news gopher nntp telnet webcal xmpp callto
|
|
89
100
|
feed svn urn aim rsync tag ssh sftp rtsp afs))
|
|
90
101
|
|
|
91
|
-
# Specifies the default Set of acceptable css
|
|
102
|
+
# Specifies the default Set of acceptable css properties that #sanitize and #sanitize_css will accept.
|
|
92
103
|
self.allowed_css_properties = Set.new(%w(azimuth background-color border-bottom-color border-collapse
|
|
93
104
|
border-color border-left-color border-right-color border-top-color clear color cursor direction display
|
|
94
105
|
elevation float font font-family font-size font-style font-variant font-weight height letter-spacing line-height
|
|
@@ -160,7 +160,7 @@ module HTML
|
|
|
160
160
|
# * <tt>:not(selector)</tt> -- Match the element only if the element does not
|
|
161
161
|
# match the simple selector.
|
|
162
162
|
#
|
|
163
|
-
# As you can see, <tt>:nth-child
|
|
163
|
+
# As you can see, <tt>:nth-child</tt> pseudo class and its variant can get quite
|
|
164
164
|
# tricky and the CSS specification doesn't do a much better job explaining it.
|
|
165
165
|
# But after reading the examples and trying a few combinations, it's easy to
|
|
166
166
|
# figure out.
|
|
@@ -537,7 +537,7 @@ module HTML
|
|
|
537
537
|
# Get identifier, class, attribute name, pseudo or negation.
|
|
538
538
|
while true
|
|
539
539
|
# Element identifier.
|
|
540
|
-
next if statement.sub!(/^#(\?|[\w\-]+)/) do
|
|
540
|
+
next if statement.sub!(/^#(\?|[\w\-]+)/) do
|
|
541
541
|
id = $1
|
|
542
542
|
if id == "?"
|
|
543
543
|
id = values.shift
|
|
@@ -549,7 +549,7 @@ module HTML
|
|
|
549
549
|
end
|
|
550
550
|
|
|
551
551
|
# Class name.
|
|
552
|
-
next if statement.sub!(/^\.([\w\-]+)/) do
|
|
552
|
+
next if statement.sub!(/^\.([\w\-]+)/) do
|
|
553
553
|
class_name = $1
|
|
554
554
|
@source << ".#{class_name}"
|
|
555
555
|
class_name = Regexp.new("(^|\s)#{Regexp.escape(class_name)}($|\s)") unless class_name.is_a?(Regexp)
|
|
@@ -558,7 +558,7 @@ module HTML
|
|
|
558
558
|
end
|
|
559
559
|
|
|
560
560
|
# Attribute value.
|
|
561
|
-
next if statement.sub!(/^\[\s*([[:alpha:]][\w\-:]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|"[^*]"|[^\]]*)\s*\]/) do
|
|
561
|
+
next if statement.sub!(/^\[\s*([[:alpha:]][\w\-:]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|"[^*]"|[^\]]*)\s*\]/) do
|
|
562
562
|
name, equality, value = $1, $2, $3
|
|
563
563
|
if value == "?"
|
|
564
564
|
value = values.shift
|
|
@@ -575,7 +575,7 @@ module HTML
|
|
|
575
575
|
end
|
|
576
576
|
|
|
577
577
|
# Root element only.
|
|
578
|
-
next if statement.sub!(/^:root/) do
|
|
578
|
+
next if statement.sub!(/^:root/) do
|
|
579
579
|
pseudo << lambda do |element|
|
|
580
580
|
element.parent.nil? || !element.parent.tag?
|
|
581
581
|
end
|
|
@@ -611,7 +611,7 @@ module HTML
|
|
|
611
611
|
"" # Remove
|
|
612
612
|
end
|
|
613
613
|
# First/last child (of type).
|
|
614
|
-
next if statement.sub!(/^:(first|last)-(child|of-type)/) do
|
|
614
|
+
next if statement.sub!(/^:(first|last)-(child|of-type)/) do
|
|
615
615
|
reverse = $1 == "last"
|
|
616
616
|
of_type = $2 == "of-type"
|
|
617
617
|
pseudo << nth_child(0, 1, of_type, reverse)
|
|
@@ -619,7 +619,7 @@ module HTML
|
|
|
619
619
|
"" # Remove
|
|
620
620
|
end
|
|
621
621
|
# Only child (of type).
|
|
622
|
-
next if statement.sub!(/^:only-(child|of-type)/) do
|
|
622
|
+
next if statement.sub!(/^:only-(child|of-type)/) do
|
|
623
623
|
of_type = $1 == "of-type"
|
|
624
624
|
pseudo << only_child(of_type)
|
|
625
625
|
@source << ":only-#{$1}"
|
|
@@ -628,7 +628,7 @@ module HTML
|
|
|
628
628
|
|
|
629
629
|
# Empty: no child elements or meaningful content (whitespaces
|
|
630
630
|
# are ignored).
|
|
631
|
-
next if statement.sub!(/^:empty/) do
|
|
631
|
+
next if statement.sub!(/^:empty/) do
|
|
632
632
|
pseudo << lambda do |element|
|
|
633
633
|
empty = true
|
|
634
634
|
for child in element.children
|
|
@@ -644,7 +644,7 @@ module HTML
|
|
|
644
644
|
end
|
|
645
645
|
# Content: match the text content of the element, stripping
|
|
646
646
|
# leading and trailing spaces.
|
|
647
|
-
next if statement.sub!(/^:content\(\s*(\?|'[^']*'|"[^"]*"|[^)]*)\s*\)/) do
|
|
647
|
+
next if statement.sub!(/^:content\(\s*(\?|'[^']*'|"[^"]*"|[^)]*)\s*\)/) do
|
|
648
648
|
content = $1
|
|
649
649
|
if content == "?"
|
|
650
650
|
content = values.shift
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/html-scanner"
|
|
2
|
+
|
|
3
|
+
module HTML
|
|
4
|
+
extend ActiveSupport::Autoload
|
|
5
|
+
|
|
6
|
+
eager_autoload do
|
|
7
|
+
autoload :CDATA, 'html/node'
|
|
8
|
+
autoload :Document, 'html/document'
|
|
9
|
+
autoload :FullSanitizer, 'html/sanitizer'
|
|
10
|
+
autoload :LinkSanitizer, 'html/sanitizer'
|
|
11
|
+
autoload :Node, 'html/node'
|
|
12
|
+
autoload :Sanitizer, 'html/sanitizer'
|
|
13
|
+
autoload :Selector, 'html/selector'
|
|
14
|
+
autoload :Tag, 'html/node'
|
|
15
|
+
autoload :Text, 'html/node'
|
|
16
|
+
autoload :Tokenizer, 'html/tokenizer'
|
|
17
|
+
autoload :Version, 'html/version'
|
|
18
|
+
autoload :WhiteListSanitizer, 'html/sanitizer'
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/action_view.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#--
|
|
2
|
-
# Copyright (c) 2004-
|
|
2
|
+
# Copyright (c) 2004-2013 David Heinemeier Hansson
|
|
3
3
|
#
|
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
5
|
# a copy of this software and associated documentation files (the
|
|
@@ -21,24 +21,24 @@
|
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
#++
|
|
23
23
|
|
|
24
|
-
require 'active_support
|
|
25
|
-
require 'active_support/
|
|
26
|
-
|
|
24
|
+
require 'active_support'
|
|
25
|
+
require 'active_support/rails'
|
|
27
26
|
require 'action_pack'
|
|
28
27
|
|
|
29
28
|
module ActionView
|
|
30
29
|
extend ActiveSupport::Autoload
|
|
31
30
|
|
|
32
31
|
eager_autoload do
|
|
33
|
-
autoload :AssetPaths
|
|
34
32
|
autoload :Base
|
|
35
33
|
autoload :Context
|
|
36
34
|
autoload :CompiledTemplates, "action_view/context"
|
|
35
|
+
autoload :Digestor
|
|
37
36
|
autoload :Helpers
|
|
38
37
|
autoload :LookupContext
|
|
39
38
|
autoload :PathSet
|
|
39
|
+
autoload :RecordIdentifier
|
|
40
|
+
autoload :RoutingUrlFor
|
|
40
41
|
autoload :Template
|
|
41
|
-
autoload :TestCase
|
|
42
42
|
|
|
43
43
|
autoload_under "renderer" do
|
|
44
44
|
autoload :Renderer
|
|
@@ -70,15 +70,24 @@ module ActionView
|
|
|
70
70
|
autoload :MissingTemplate
|
|
71
71
|
autoload :ActionViewError
|
|
72
72
|
autoload :EncodingError
|
|
73
|
+
autoload :MissingRequestError
|
|
73
74
|
autoload :TemplateError
|
|
74
75
|
autoload :WrongEncodingError
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
|
|
79
|
+
autoload :TestCase
|
|
80
|
+
|
|
78
81
|
ENCODING_FLAG = '#.*coding[:=]\s*(\S+)[ \t]*'
|
|
82
|
+
|
|
83
|
+
def self.eager_load!
|
|
84
|
+
super
|
|
85
|
+
ActionView::Template.eager_load!
|
|
86
|
+
end
|
|
79
87
|
end
|
|
80
88
|
|
|
81
|
-
require 'active_support/i18n'
|
|
82
89
|
require 'active_support/core_ext/string/output_safety'
|
|
83
90
|
|
|
84
|
-
|
|
91
|
+
ActiveSupport.on_load(:i18n) do
|
|
92
|
+
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
|
|
93
|
+
end
|