Commit Graph

2867 Commits

Author SHA1 Message Date
Shouichi Kamiya
aaa9bcc62e Document that url_for can take classes
Co-authored-by: oljfte <oljfte@gmail.com>
2022-05-13 10:09:17 +09:00
Jean Boussier
dd0b302378
Merge pull request #45029 from jonathanhefner/fix-extract_dimensions-regexp
Escape literal dot in regular expression
2022-05-09 09:55:00 +02:00
Jonathan Hefner
fe24f5880d Escape literal dot in regular expression
Follow-up to #44669.

This ensures that e.g. sizes with commas are not erroneously matched.
2022-05-05 14:08:43 -05:00
eileencodes
944bcb54f6
Fix tag helper regression
Vue.js, alpinejs, and potentially other JS libraries support tags
starting with `@` symbols. This was broken by the recent security release in
649516ce0f

I've only added `@` to the list even though there are potentially other
safe characters. We can add more if necessary (and if safe).

Fixes:
* #45014
* #44972
2022-05-05 10:42:41 -04:00
Alvaro Martin Fraguas
649516ce0f
Fix and add protections for XSS in names.
Add the method ERB::Util.xml_name_escape to escape dangerous characters
in names of tags and names of attributes, following the specification of
XML.

Use that method in the tag helpers of ActionView::Helpers. Rename the option
:escape_attributes to :escape, to simplify by applying the option to the whole
tag.
2022-04-26 12:34:42 -07:00
Xavier Noria
2953ae5c8a Define config.enable_reloading to be !config.cache_classes
Every time I write `config.cache_classes` I have to pause for a moment to make
sure I get it right. It makes you think.

On the other hand, if you read `config.enable_reloading = true`, does the
application reload? You do not need to spend 1 cycle of brain CPU to nod.
2022-04-14 18:11:36 +02:00
Jonathan Hefner
255accb0a5 Fix button_to UJS examples formatting [ci-skip]
Because the indented code block follows an indented list item, RDoc
interprets the examples as a continuation of the list item prose,
instead of code.  To distinguish the two, this commit moves the examples
to their own subsection with an intervening subheading.

Additionally, this commit applies a few other formatting tweaks.
2022-04-11 15:35:58 -05:00
Jonathan Hefner
7ad1bc8845 Fix link_to UJS examples formatting [ci-skip]
Because the indented code block follows an indented list item, RDoc
interprets the examples as a continuation of the list item prose,
instead of code.  To distinguish the two, this commit moves the examples
to their own subsection with an intervening subheading.

Additionally, this commit applies a few other formatting tweaks.
2022-04-11 15:35:24 -05:00
Jonathan Hefner
eea6f4dc81
Merge pull request #44784 from ghiculescu/data-remote-no-turbo
Document that `data-remote` and `data-method` are deprecated [ci-skip]
2022-04-11 15:27:35 -05:00
Alex Ghiculescu
be746b2623 Document that data-remote and data-method are deprecated
Follow up to https://github.com/rails/rails/pull/43112 and https://github.com/rails/rails/pull/44100

- `data-remote` is deprecated on links and buttons. Turbo doesn't need it since that is the default behaviour. You use `data-turbo=false` on elements that opt out of that, but I don't think that's in scope for Rails.
- `data-method` is deprecated on links. Turbo expects [data-turbo-method](https://turbo.hotwired.dev/handbook/drive#performing-visits-with-a-different-method).

Update actionview/lib/action_view/helpers/url_helper.rb

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>

Update actionview/lib/action_view/helpers/url_helper.rb

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2022-04-11 13:03:14 -05:00
Ryuta Kamizono
714fd07fd9 All intermediate delegation methods should preserve kwargs flag
Since 0456826180,
`foo(*caller_args)` method call delegation no longer preserve kwargs
flag.

Fixes #44846.
2022-04-06 15:32:54 +09:00
John Bampton
ad91029117 Change rss to RSS in ImageLinkToTag 2022-04-01 12:05:28 +10:00
John Bampton
c38d585ef0 Fix word casing of XHTML and XML Builder
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2022-03-30 04:21:59 +10:00
Rafael Mendonça França
5c1bd20f0d
Merge pull request #44693 from ghousemohamed/fix-docs-related-gem-versions
Fix `#version` method docs and some typos [ci-skip]
2022-03-15 16:28:07 -04:00
Ghouse Mohamed
6ee6cb554b Fix #version docs and some typos 2022-03-16 01:48:37 +05:30
Aaron Patterson
8961b8ece7
Merge pull request #44669 from kaiquekandykoga/extract-float
Extract float
2022-03-14 15:16:06 -07:00
Kaíque Kandy Koga
16e6d77200 Extract float numbers when using size option
for image_tag and video_tag

Delete space

format_numbers number_formats

Add tests

Change tests

Use regex in extract_dimensations
2022-03-14 14:11:07 -03:00
Aaron Patterson
d28efa55fa
Merge pull request #43975 from codergeek121/bugfix-for-time-select-prompt
Fix a bug with time_select and prompts
2022-03-14 09:44:42 -07:00
Matheus Richard
414394206a Extend audio_tag and video_tag to accept Active Storage attachments.
Now it's possible to write

    audio_tag(user.audio_file)
    video_tag(user.video_file)

Instead of

    audio_tag(polymorphic_path(user.audio_file))
    video_tag(polymorphic_path(user.video_file))

image_tag already supported that, so this follows the same pattern.
2022-03-14 02:05:37 -03:00
Jean Boussier
13dd6f93c8
Merge pull request #44585 from davekaro/remove_circle_void_element
Remove circle from HTML_VOID_ELEMENTS set.
2022-03-02 20:26:45 +01:00
Jean Boussier
2fd34270eb Eager load controllers view_context_class
These classes are relatively small, however they include lots of
modules as helpers. And if any of the included module hold constants
including it cause the global constant cache to be invalidated
which is really bad for performance.

So when eager loading is enabled we create all the possible classes
as part of the application boot.
2022-03-02 08:47:54 +01:00
Dave Kroondyk
8d51706c20 Remove circle from HTML_VOID_ELEMENTS set.
`<circle>` is in the SVG_SELF_CLOSING_ELEMENTS list and is not a void element according to
'https://html.spec.whatwg.org/multipage/syntax.html#void-elements'.
2022-03-01 09:08:23 -05:00
Dave Kroondyk
3814826885 Ensure SVG elements are closed.
Changes introduced in https://github.com/rails/rails/pull/43232 break SVGs
that have mulitple of the same descendant tag because they weren't being
closed. SVG elements must be closed accodoring to spec
https://html.spec.whatwg.org/multipage/syntax.html#elements-2.

Fixes https://github.com/rails/rails/issues/44563
2022-02-28 17:52:02 -05:00
Rafael Mendonça França
201aecb260
Merge pull request #44555 from koic/enable_style_map_to_hash_cop
Enable `Style/MapToHash` cop
2022-02-25 15:23:50 -05:00
Rafael Mendonça França
b64cbc0b27
Merge pull request #44529 from Shopify/actionview-fix-flaky-tests
Fix flaky Action View tests
2022-02-25 14:47:49 -05:00
Koichi ITO
819871cc4e Enable Style/MapToHash cop
Ruby 2.6 added block argument processing to `Enumerable#to_h`.
https://bugs.ruby-lang.org/issues/15143

Rails 7 requires Ruby 2.7.0 or higher, so the new feature can use it.
`Style/MapToHash` cop will detect it. And this cop in the `Style` department,
but this seems to improve performance as follows:

```ruby
# map_to_hash.rb
require 'benchmark/ips'

ARRAY = (1..100).to_a
HASH = {foo: 1, bar: 2}

Benchmark.ips do |x|
  x.report('array.map.to_h') { ARRAY.map { |v| [v, v * 2] }.to_h }
  x.report('array.to_h')     { ARRAY.to_h { |v| [v, v * 2] } }

  x.compare!
end

Benchmark.ips do |x|
  x.report('hash.map.to_h') { HASH.map { |k, v| [k.to_s, v * 2] }.to_h }
  x.report('hash.to_h')     { HASH.to_h { |k, v| [k.to_s, v * 2] } }

  x.compare!
end
```

```console
% ruby map_to_hash.rb
Warming up --------------------------------------
      array.map.to_h     9.063k i/100ms
          array.to_h     9.609k i/100ms
Calculating -------------------------------------
      array.map.to_h     89.063k (± 3.9%) i/s -    453.150k in  5.096572s
          array.to_h     96.449k (± 1.7%) i/s -    490.059k in  5.082529s

Comparison:
          array.to_h:    96448.7 i/s
      array.map.to_h:    89063.4 i/s - 1.08x  (± 0.00) slower

Warming up --------------------------------------
       hash.map.to_h   106.284k i/100ms
           hash.to_h   149.354k i/100ms
Calculating -------------------------------------
       hash.map.to_h      1.102M (± 2.2%) i/s -      5.527M in   5.019657s
           hash.to_h      1.490M (± 0.9%) i/s -      7.468M in   5.013264s

Comparison:
           hash.to_h:  1489707.0 i/s
       hash.map.to_h:  1101561.5 i/s - 1.35x  (± 0.00) slower
```

`Style/MapToHash` cop ... https://docs.rubocop.org/rubocop/1.25/cops_style.html#stylemaptohash
2022-02-26 04:31:03 +09:00
Clayton Smith
6e56e18523 Fix flaky Action View tests 2022-02-23 09:39:57 -05:00
Jonathan Hefner
a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jonathan Hefner
9dbf7a58a2 Fix formatting of parameters doc [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
a801aa7cde Mark up inline code [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
07bee949c4 Replace backticks with RDoc markup [ci-skip]
RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2022-02-21 11:11:11 -06:00
Jonathan Hefner
0d3effc97e Replace "overwrite" with "override" [ci-skip]
"Overwrite" means "destructively replace", and is more suitable when,
for example, talking about writing data to a location.

"Override" means "supersede", and is more suitable when, for example,
talking about redifining methods in a subclass.
2022-02-21 11:11:11 -06:00
Jonathan Hefner
5fdbd217d1 Fix typos [ci-skip] 2022-02-21 11:11:11 -06:00
Jean Boussier
e26372b713 Implicitly assert no exception is raised in assert_queries & al
Fix: https://github.com/rails/rails/pull/44397
Ref: https://github.com/rails/rails/pull/37313
Ref: https://github.com/rails/rails/pull/42459

This avoid mistakes such as:

```ruby
assert_raise Something do
  assert_queries(1) do
    raise Something
  end
end
```

Co-Authored-By: Alex Coomans <alexc@squareup.com>
2022-02-19 09:11:14 +01:00
Sean Doyle
9dc083f95d form_for: Attempt to call to_model on record
Related to https://github.com/rails/rails/issues/44326

---

The changes introduced in [rails/rails#43421][] did not account for
attempting to coerce the record with [#to_model][]. This commit resolves
that issue and adds test coverage to guard against future regressions.

Additionally, this adds tests to exercise `form_with` to ensure that it
_does not_ call `#to_model` on its `model:` argument, since that was the
behavior in [6.1.4.4][]

[rails/rails#43421]: https://github.com/rails/rails/pull/43421
[#to_model]: https://edgeapi.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_model
[6.1.4.4]: https://github.com/rails/rails/issues/44326#issuecomment-1029344241
2022-02-17 16:01:57 -05:00
John Hawthorn
3e2f9a66db
Merge pull request #43390 from jhawthorn/remove_notification_event_children
Remove child event tracking from ActiveSupport::Subscriber
2022-02-17 08:45:48 -08:00
John Hawthorn
139ef8a0bc
Merge pull request #44174 from jguecaimburu/add_lowdash_support_to_path_parser_locale_regex
Add support to locales with lowdash in Resolver::PathParser
2022-02-17 08:27:34 -08:00
John Hawthorn
9c58a54702 Split actionview log subscriber Start events
Previously one subscriber was used for both the "Rendering" (before) and
"Rendered" (after) events. With the previous change to AS::Subscriber
these need to be split.

Co-authored-by: Adam Hess <HParker@github.com>
2022-02-17 08:20:01 -08:00
Rafael Mendonça França
b961af3345
Merge pull request #44093 from motine/doc-hint-for-fields_for
add hint to ActionView's fields_for
2022-02-09 20:17:01 -05:00
Ryuta Kamizono
135f41d0b0
Merge pull request #44337 from paulhenri-l/patch-1
Fix empty request inside helpers test
2022-02-09 17:33:40 +09:00
Paul-Henri Leobon
867e60f6c2
Fix empty request inside helpers test
During testing view helpers do not have access to the `request` object but they do when used inside of a view.

If we were to test a helper like this one :

```ruby
  def active?(test_path)
    request.path.match? test_path
  end
```

we would get this error : 

```
NoMethodError: undefined method `path' for nil:NilClass
```

Adding `:request` to the attr_accessor will make tests consistent with the default behavior.
2022-02-09 08:47:27 +01:00
Tom Rothe
c6cb78349a add hint to ActionView's fields_for 2022-02-08 22:09:08 +01:00
David Heinemeier Hansson
41478f7074 Make #to_fs the default replacement for #to_s(:format)
#to_formatted_s is too cumbersome.
2022-02-07 12:41:21 +01:00
Jonathan Hefner
9648e89511 Fix test_tag_attributes_escapes_values assertion
The 1st argument to `assert_not_includes` is the collection to search;
the 2nd argument is the element to search for.  Thus this test was
checking if the output was included in the forbidden string, rather than
checking the if the forbidden string was included in the output.

Because negative assertions like this one can be fooled more easily,
this commit changes the test to use `assert_equal`, as the other tests
do.
2022-01-29 12:10:14 -06:00
Gannon McGibbon
aaa64687e8
Revert #38957 (#44287)
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289dbbe146c56ec16faf8dd1a2c88611feb83.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4de6ef89c285833a90dd23db25cad7b669.
2022-01-29 14:27:45 +01:00
Yasuo Honda
d6f96a9d7c Address ActionView::Template::Error
This commit addresses the following CI error.
https://buildkite.com/rails/rails/builds/84207#3bc8eb7f-c86d-4f6f-8932-e2e8c26cf893

There were similar pull requests #36189 #39949

```ruby
$ bin/test test/template/test_case_test.rb test/template/render_test.rb -n "/^(?:ActionView::HelperInclusionTest#(?:test_helper_class_that_is_being_tested_is_always_included_in_view_instance)|FrozenStringLiteralEnabledViewRenderTest#(?:test_render_partial_collection_for_non_array))$/" --seed 41598
Run options: -n "/^(?:ActionView::HelperInclusionTest#(?:test_helper_class_that_is_being_tested_is_always_included_in_view_instance)|FrozenStringLiteralEnabledViewRenderTest#(?:test_render_partial_collection_for_non_array))$/" --seed 41598

.E

Error:
FrozenStringLiteralEnabledViewRenderTest#test_render_partial_collection_for_non_array:
ActionView::Template::Error: undefined method `__home_yahonda_src_github_com_rails_rails_actionview_test_fixtures_test__customer_erb__1256308179417979847_7880' for #<ActionView::Base:0x00000000003de0>
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:244:in `public_send'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:244:in `_run'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:157:in `block in render'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:208:in `instrument'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:361:in `instrument_render_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:155:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:189:in `block in collection_with_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `block in each_with_info'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:385:in `yield'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:385:in `block in test_render_partial_collection_for_non_array'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each_with_info'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `map'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `collection_with_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:162:in `block (2 levels) in render_collection'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb:21:in `cache_collection_render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:161:in `block in render_collection'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `block in instrument'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `instrument'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:147:in `render_collection'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:119:in `render_collection_with_partial'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:72:in `render_partial_to_object'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:27:in `render_to_object'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:22:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/helpers/rendering_helper.rb:38:in `block in render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:270:in `in_rendering_context'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/helpers/rendering_helper.rb:34:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:388:in `test_render_partial_collection_for_non_array'

bin/test test/template/render_test.rb:383

Finished in 0.047002s, 42.5514 runs/s, 63.8271 assertions/s.
2 runs, 3 assertions, 0 failures, 1 errors, 0 skips
$
```
2022-01-27 16:36:27 +09:00
Shunichi Ikegami
a692bb628c Fix typos and remove unused options in DateTimeSelector 2022-01-25 09:51:52 +09:00
Alex Ghiculescu
85b533308f
Document that @rails/ujs is deprecated for button_to (#44100)
* Document that @rails/ujs is deprecated for `button_to`

This was missed in https://github.com/rails/rails/pull/43112

* deprecation needs to go below the examples
2022-01-20 12:23:37 +01:00
Rafael Mendonça França
c777afb242
Merge pull request #44198 from ElMassimo/preload-modules
Ensure preload_link_tag preloads modules correctly
2022-01-19 21:12:26 -05:00