actionview 5.2.4.4 → 6.0.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 actionview might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +106 -91
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/action_view.rb +1 -1
  6. data/lib/action_view/buffers.rb +15 -0
  7. data/lib/action_view/context.rb +5 -4
  8. data/lib/action_view/digestor.rb +7 -6
  9. data/lib/action_view/gem_version.rb +4 -4
  10. data/lib/action_view/helpers.rb +0 -2
  11. data/lib/action_view/helpers/asset_tag_helper.rb +4 -27
  12. data/lib/action_view/helpers/asset_url_helper.rb +4 -3
  13. data/lib/action_view/helpers/cache_helper.rb +18 -10
  14. data/lib/action_view/helpers/capture_helper.rb +4 -0
  15. data/lib/action_view/helpers/csrf_helper.rb +1 -1
  16. data/lib/action_view/helpers/date_helper.rb +69 -25
  17. data/lib/action_view/helpers/form_helper.rb +240 -8
  18. data/lib/action_view/helpers/form_options_helper.rb +23 -15
  19. data/lib/action_view/helpers/form_tag_helper.rb +9 -9
  20. data/lib/action_view/helpers/javascript_helper.rb +10 -11
  21. data/lib/action_view/helpers/number_helper.rb +5 -0
  22. data/lib/action_view/helpers/sanitize_helper.rb +3 -3
  23. data/lib/action_view/helpers/tag_helper.rb +7 -6
  24. data/lib/action_view/helpers/tags/base.rb +8 -4
  25. data/lib/action_view/helpers/tags/color_field.rb +1 -1
  26. data/lib/action_view/helpers/tags/translator.rb +1 -6
  27. data/lib/action_view/helpers/text_helper.rb +3 -3
  28. data/lib/action_view/helpers/translation_helper.rb +11 -18
  29. data/lib/action_view/helpers/url_helper.rb +14 -14
  30. data/lib/action_view/log_subscriber.rb +6 -6
  31. data/lib/action_view/lookup_context.rb +4 -4
  32. data/lib/action_view/railtie.rb +18 -0
  33. data/lib/action_view/record_identifier.rb +2 -2
  34. data/lib/action_view/renderer/partial_renderer.rb +2 -2
  35. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +40 -1
  36. data/lib/action_view/renderer/streaming_template_renderer.rb +1 -1
  37. data/lib/action_view/rendering.rb +5 -4
  38. data/lib/action_view/routing_url_for.rb +12 -11
  39. data/lib/action_view/template.rb +25 -8
  40. data/lib/action_view/template/handlers/erb.rb +12 -2
  41. data/lib/action_view/template/resolver.rb +56 -16
  42. data/lib/action_view/test_case.rb +1 -1
  43. data/lib/action_view/testing/resolvers.rb +1 -1
  44. data/lib/assets/compiled/rails-ujs.js +39 -22
  45. metadata +14 -15
  46. data/lib/action_view/helpers/record_tag_helper.rb +0 -23
@@ -14,7 +14,17 @@ module ActionView
14
14
  class_attribute :erb_implementation, default: Erubi
15
15
 
16
16
  # Do not escape templates of these mime types.
17
- class_attribute :escape_whitelist, default: ["text/plain"]
17
+ class_attribute :escape_ignore_list, default: ["text/plain"]
18
+
19
+ [self, singleton_class].each do |base|
20
+ base.alias_method :escape_whitelist, :escape_ignore_list
21
+ base.alias_method :escape_whitelist=, :escape_ignore_list=
22
+
23
+ base.deprecate(
24
+ escape_whitelist: "use #escape_ignore_list instead",
25
+ :escape_whitelist= => "use #escape_ignore_list= instead"
26
+ )
27
+ end
18
28
 
19
29
  ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
20
30
 
@@ -47,7 +57,7 @@ module ActionView
47
57
 
48
58
  self.class.erb_implementation.new(
49
59
  erb,
50
- escape: (self.class.escape_whitelist.include? template.type),
60
+ escape: (self.class.escape_ignore_list.include? template.type),
51
61
  trim: (self.class.erb_trim_mode == "-")
52
62
  ).src
53
63
  end
@@ -16,7 +16,7 @@ module ActionView
16
16
  alias_method :partial?, :partial
17
17
 
18
18
  def self.build(name, prefix, partial)
19
- virtual = "".dup
19
+ virtual = +""
20
20
  virtual << "#{prefix}/" unless prefix.empty?
21
21
  virtual << (partial ? "_#{name}" : name)
22
22
  new name, prefix, partial, virtual
@@ -221,9 +221,7 @@ module ActionView
221
221
  end
222
222
 
223
223
  def query(path, details, formats, outside_app_allowed)
224
- query = build_query(path, details)
225
-
226
- template_paths = find_template_paths(query)
224
+ template_paths = find_template_paths_from_details(path, details)
227
225
  template_paths = reject_files_external_to_app(template_paths) unless outside_app_allowed
228
226
 
229
227
  template_paths.map do |template|
@@ -243,6 +241,11 @@ module ActionView
243
241
  files.reject { |filename| !inside_path?(@path, filename) }
244
242
  end
245
243
 
244
+ def find_template_paths_from_details(path, details)
245
+ query = build_query(path, details)
246
+ find_template_paths(query)
247
+ end
248
+
246
249
  def find_template_paths(query)
247
250
  Dir[query].uniq.reject do |filename|
248
251
  File.directory?(filename) ||
@@ -279,7 +282,7 @@ module ActionView
279
282
  end
280
283
 
281
284
  def escape_entry(entry)
282
- entry.gsub(/[*?{}\[\]]/, '\\\\\\&'.freeze)
285
+ entry.gsub(/[*?{}\[\]]/, '\\\\\\&')
283
286
  end
284
287
 
285
288
  # Returns the file mtime from the filesystem.
@@ -291,7 +294,7 @@ module ActionView
291
294
  # from the path, or the handler, we should return the array of formats given
292
295
  # to the resolver.
293
296
  def extract_handler_and_format_and_variant(path)
294
- pieces = File.basename(path).split(".".freeze)
297
+ pieces = File.basename(path).split(".")
295
298
  pieces.shift
296
299
 
297
300
  extension = pieces.pop
@@ -362,19 +365,56 @@ module ActionView
362
365
 
363
366
  # An Optimized resolver for Rails' most common case.
364
367
  class OptimizedFileSystemResolver < FileSystemResolver #:nodoc:
365
- def build_query(path, details)
366
- query = escape_entry(File.join(@path, path))
368
+ private
367
369
 
368
- exts = EXTENSIONS.map do |ext, prefix|
369
- if ext == :variants && details[ext] == :any
370
- "{#{prefix}*,}"
371
- else
372
- "{#{details[ext].compact.uniq.map { |e| "#{prefix}#{e}," }.join}}"
370
+ def find_template_paths_from_details(path, details)
371
+ # Instead of checking for every possible path, as our other globs would
372
+ # do, scan the directory for files with the right prefix.
373
+ query = "#{escape_entry(File.join(@path, path))}*"
374
+
375
+ regex = build_regex(path, details)
376
+
377
+ Dir[query].uniq.reject do |filename|
378
+ # This regex match does double duty of finding only files which match
379
+ # details (instead of just matching the prefix) and also filtering for
380
+ # case-insensitive file systems.
381
+ !regex.match?(filename) ||
382
+ File.directory?(filename)
383
+ end.sort_by do |filename|
384
+ # Because we scanned the directory, instead of checking for files
385
+ # one-by-one, they will be returned in an arbitrary order.
386
+ # We can use the matches found by the regex and sort by their index in
387
+ # details.
388
+ match = filename.match(regex)
389
+ EXTENSIONS.keys.reverse.map do |ext|
390
+ if ext == :variants && details[ext] == :any
391
+ match[ext].nil? ? 0 : 1
392
+ elsif match[ext].nil?
393
+ # No match should be last
394
+ details[ext].length
395
+ else
396
+ found = match[ext].to_sym
397
+ details[ext].index(found)
398
+ end
399
+ end
373
400
  end
374
- end.join
401
+ end
375
402
 
376
- query + exts
377
- end
403
+ def build_regex(path, details)
404
+ query = escape_entry(File.join(@path, path))
405
+ exts = EXTENSIONS.map do |ext, prefix|
406
+ match =
407
+ if ext == :variants && details[ext] == :any
408
+ ".*?"
409
+ else
410
+ details[ext].compact.uniq.map { |e| Regexp.escape(e) }.join("|")
411
+ end
412
+ prefix = Regexp.escape(prefix)
413
+ "(#{prefix}(?<#{ext}>#{match}))?"
414
+ end.join
415
+
416
+ %r{\A#{query}#{exts}\z}
417
+ end
378
418
  end
379
419
 
380
420
  # The same as FileSystemResolver but does not allow templates to store
@@ -107,7 +107,7 @@ module ActionView
107
107
  # empty string ensures buffer has UTF-8 encoding as
108
108
  # new without arguments returns ASCII-8BIT encoded buffer like String#new
109
109
  @output_buffer = ActiveSupport::SafeBuffer.new ""
110
- @rendered = "".dup
110
+ @rendered = +""
111
111
 
112
112
  make_test_case_available_to_view!
113
113
  say_no_to_protect_against_forgery!
@@ -22,7 +22,7 @@ module ActionView #:nodoc:
22
22
  private
23
23
 
24
24
  def query(path, exts, _, _)
25
- query = "".dup
25
+ query = +""
26
26
  EXTENSIONS.each_key do |ext|
27
27
  query << "(" << exts[ext].map { |e| e && Regexp.escape(".#{e}") }.join("|") << "|)"
28
28
  end
@@ -2,7 +2,7 @@
2
2
  Unobtrusive JavaScript
3
3
  https://github.com/rails/rails/blob/master/actionview/app/assets/javascripts
4
4
  Released under the MIT license
5
- */;
5
+ */
6
6
 
7
7
  (function() {
8
8
  var context = this;
@@ -32,17 +32,12 @@ Released under the MIT license
32
32
 
33
33
  (function() {
34
34
  (function() {
35
- var nonce;
35
+ var cspNonce;
36
36
 
37
- nonce = null;
38
-
39
- Rails.loadCSPNonce = function() {
40
- var ref;
41
- return nonce = (ref = document.querySelector("meta[name=csp-nonce]")) != null ? ref.content : void 0;
42
- };
43
-
44
- Rails.cspNonce = function() {
45
- return nonce != null ? nonce : Rails.loadCSPNonce();
37
+ cspNonce = Rails.cspNonce = function() {
38
+ var meta;
39
+ meta = document.querySelector('meta[name=csp-nonce]');
40
+ return meta && meta.content;
46
41
  };
47
42
 
48
43
  }).call(this);
@@ -247,8 +242,8 @@ Released under the MIT license
247
242
  }
248
243
  if (!options.crossDomain) {
249
244
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
250
- CSRFProtection(xhr);
251
245
  }
246
+ CSRFProtection(xhr);
252
247
  xhr.withCredentials = !!options.withCredentials;
253
248
  xhr.onreadystatechange = function() {
254
249
  if (xhr.readyState === XMLHttpRequest.DONE) {
@@ -270,7 +265,7 @@ Released under the MIT license
270
265
  script.setAttribute('nonce', cspNonce());
271
266
  script.text = response;
272
267
  document.head.appendChild(script).parentNode.removeChild(script);
273
- } else if (type.match(/\b(xml|html|svg)\b/)) {
268
+ } else if (type.match(/\bxml\b/)) {
274
269
  parser = new DOMParser();
275
270
  type = type.replace(/;.+/, '');
276
271
  try {
@@ -370,6 +365,10 @@ Released under the MIT license
370
365
  }
371
366
  };
372
367
 
368
+ Rails.confirm = function(message, element) {
369
+ return confirm(message);
370
+ };
371
+
373
372
  allowAction = function(element) {
374
373
  var answer, callback, message;
375
374
  message = element.getAttribute('data-confirm');
@@ -379,7 +378,7 @@ Released under the MIT license
379
378
  answer = false;
380
379
  if (fire(element, 'confirm')) {
381
380
  try {
382
- answer = confirm(message);
381
+ answer = Rails.confirm(message, element);
383
382
  } catch (error) {}
384
383
  callback = fire(element, 'confirm:complete', [answer]);
385
384
  }
@@ -388,7 +387,7 @@ Released under the MIT license
388
387
 
389
388
  }).call(this);
390
389
  (function() {
391
- var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, matches, setData, stopEverything;
390
+ var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, isXhrRedirect, matches, setData, stopEverything;
392
391
 
393
392
  matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, stopEverything = Rails.stopEverything, formElements = Rails.formElements;
394
393
 
@@ -402,7 +401,14 @@ Released under the MIT license
402
401
 
403
402
  Rails.enableElement = function(e) {
404
403
  var element;
405
- element = e instanceof Event ? e.target : e;
404
+ if (e instanceof Event) {
405
+ if (isXhrRedirect(e)) {
406
+ return;
407
+ }
408
+ element = e.target;
409
+ } else {
410
+ element = e;
411
+ }
406
412
  if (matches(element, Rails.linkDisableSelector)) {
407
413
  return enableLinkElement(element);
408
414
  } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formEnableSelector)) {
@@ -426,6 +432,9 @@ Released under the MIT license
426
432
 
427
433
  disableLinkElement = function(element) {
428
434
  var replacement;
435
+ if (getData(element, 'ujs:disabled')) {
436
+ return;
437
+ }
429
438
  replacement = element.getAttribute('data-disable-with');
430
439
  if (replacement != null) {
431
440
  setData(element, 'ujs:enable-with', element.innerHTML);
@@ -452,6 +461,9 @@ Released under the MIT license
452
461
 
453
462
  disableFormElement = function(element) {
454
463
  var replacement;
464
+ if (getData(element, 'ujs:disabled')) {
465
+ return;
466
+ }
455
467
  replacement = element.getAttribute('data-disable-with');
456
468
  if (replacement != null) {
457
469
  if (matches(element, 'button')) {
@@ -485,6 +497,12 @@ Released under the MIT license
485
497
  return setData(element, 'ujs:disabled', null);
486
498
  };
487
499
 
500
+ isXhrRedirect = function(event) {
501
+ var ref, xhr;
502
+ xhr = (ref = event.detail) != null ? ref[0] : void 0;
503
+ return (xhr != null ? xhr.getResponseHeader("X-Xhr-Redirect") : void 0) != null;
504
+ };
505
+
488
506
  }).call(this);
489
507
  (function() {
490
508
  var stopEverything;
@@ -622,23 +640,23 @@ Released under the MIT license
622
640
  };
623
641
 
624
642
  Rails.preventInsignificantClick = function(e) {
625
- var data, insignificantMetaClick, link, metaClick, method, nonPrimaryMouseClick;
643
+ var data, insignificantMetaClick, link, metaClick, method, primaryMouseKey;
626
644
  link = this;
627
645
  method = (link.getAttribute('data-method') || 'GET').toUpperCase();
628
646
  data = link.getAttribute('data-params');
629
647
  metaClick = e.metaKey || e.ctrlKey;
630
648
  insignificantMetaClick = metaClick && method === 'GET' && !data;
631
- nonPrimaryMouseClick = (e.button != null) && e.button !== 0;
632
- if (nonPrimaryMouseClick || insignificantMetaClick) {
649
+ primaryMouseKey = e.button === 0;
650
+ if (!primaryMouseKey || insignificantMetaClick) {
633
651
  return e.stopImmediatePropagation();
634
652
  }
635
653
  };
636
654
 
637
655
  }).call(this);
638
656
  (function() {
639
- var $, CSRFProtection, delegate, disableElement, enableElement, fire, formSubmitButtonClick, getData, handleConfirm, handleDisabledElement, handleMethod, handleRemote, loadCSPNonce, preventInsignificantClick, refreshCSRFTokens;
657
+ var $, CSRFProtection, delegate, disableElement, enableElement, fire, formSubmitButtonClick, getData, handleConfirm, handleDisabledElement, handleMethod, handleRemote, preventInsignificantClick, refreshCSRFTokens;
640
658
 
641
- fire = Rails.fire, delegate = Rails.delegate, getData = Rails.getData, $ = Rails.$, refreshCSRFTokens = Rails.refreshCSRFTokens, CSRFProtection = Rails.CSRFProtection, loadCSPNonce = Rails.loadCSPNonce, enableElement = Rails.enableElement, disableElement = Rails.disableElement, handleDisabledElement = Rails.handleDisabledElement, handleConfirm = Rails.handleConfirm, preventInsignificantClick = Rails.preventInsignificantClick, handleRemote = Rails.handleRemote, formSubmitButtonClick = Rails.formSubmitButtonClick, handleMethod = Rails.handleMethod;
659
+ fire = Rails.fire, delegate = Rails.delegate, getData = Rails.getData, $ = Rails.$, refreshCSRFTokens = Rails.refreshCSRFTokens, CSRFProtection = Rails.CSRFProtection, enableElement = Rails.enableElement, disableElement = Rails.disableElement, handleDisabledElement = Rails.handleDisabledElement, handleConfirm = Rails.handleConfirm, preventInsignificantClick = Rails.preventInsignificantClick, handleRemote = Rails.handleRemote, formSubmitButtonClick = Rails.formSubmitButtonClick, handleMethod = Rails.handleMethod;
642
660
 
643
661
  if ((typeof jQuery !== "undefined" && jQuery !== null) && (jQuery.ajax != null)) {
644
662
  if (jQuery.rails) {
@@ -701,7 +719,6 @@ Released under the MIT license
701
719
  delegate(document, Rails.formInputClickSelector, 'click', handleConfirm);
702
720
  delegate(document, Rails.formInputClickSelector, 'click', formSubmitButtonClick);
703
721
  document.addEventListener('DOMContentLoaded', refreshCSRFTokens);
704
- document.addEventListener('DOMContentLoaded', loadCSPNonce);
705
722
  return window._rails_loaded = true;
706
723
  };
707
724
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.4.4
4
+ version: 6.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.4.4
19
+ version: 6.0.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.4.4
26
+ version: 6.0.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,28 +92,28 @@ dependencies:
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 5.2.4.4
95
+ version: 6.0.0.beta1
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
- version: 5.2.4.4
102
+ version: 6.0.0.beta1
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: activemodel
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: 5.2.4.4
109
+ version: 6.0.0.beta1
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - '='
115
115
  - !ruby/object:Gem::Version
116
- version: 5.2.4.4
116
+ version: 6.0.0.beta1
117
117
  description: Simple, battle-tested conventions and helpers for building web pages.
118
118
  email: david@loudthinking.com
119
119
  executables: []
@@ -149,7 +149,6 @@ files:
149
149
  - lib/action_view/helpers/javascript_helper.rb
150
150
  - lib/action_view/helpers/number_helper.rb
151
151
  - lib/action_view/helpers/output_safety_helper.rb
152
- - lib/action_view/helpers/record_tag_helper.rb
153
152
  - lib/action_view/helpers/rendering_helper.rb
154
153
  - lib/action_view/helpers/sanitize_helper.rb
155
154
  - lib/action_view/helpers/tag_helper.rb
@@ -230,8 +229,8 @@ homepage: http://rubyonrails.org
230
229
  licenses:
231
230
  - MIT
232
231
  metadata:
233
- source_code_uri: https://github.com/rails/rails/tree/v5.2.4.4/actionview
234
- changelog_uri: https://github.com/rails/rails/blob/v5.2.4.4/actionview/CHANGELOG.md
232
+ source_code_uri: https://github.com/rails/rails/tree/v6.0.0.beta1/actionview
233
+ changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta1/actionview/CHANGELOG.md
235
234
  post_install_message:
236
235
  rdoc_options: []
237
236
  require_paths:
@@ -240,15 +239,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
239
  requirements:
241
240
  - - ">="
242
241
  - !ruby/object:Gem::Version
243
- version: 2.2.2
242
+ version: 2.5.0
244
243
  required_rubygems_version: !ruby/object:Gem::Requirement
245
244
  requirements:
246
- - - ">="
245
+ - - ">"
247
246
  - !ruby/object:Gem::Version
248
- version: '0'
247
+ version: 1.3.1
249
248
  requirements:
250
249
  - none
251
- rubygems_version: 3.1.2
250
+ rubygems_version: 3.0.1
252
251
  signing_key:
253
252
  specification_version: 4
254
253
  summary: Rendering framework putting the V in MVC (part of Rails).
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Helpers #:nodoc:
5
- module RecordTagHelper
6
- def div_for(*) # :nodoc:
7
- raise NoMethodError, "The `div_for` method has been removed from " \
8
- "Rails. To continue using it, add the `record_tag_helper` gem to " \
9
- "your Gemfile:\n" \
10
- " gem 'record_tag_helper', '~> 1.0'\n" \
11
- "Consult the Rails upgrade guide for details."
12
- end
13
-
14
- def content_tag_for(*) # :nodoc:
15
- raise NoMethodError, "The `content_tag_for` method has been removed from " \
16
- "Rails. To continue using it, add the `record_tag_helper` gem to " \
17
- "your Gemfile:\n" \
18
- " gem 'record_tag_helper', '~> 1.0'\n" \
19
- "Consult the Rails upgrade guide for details."
20
- end
21
- end
22
- end
23
- end