Commit Graph

2690 Commits

Author SHA1 Message Date
Ryuta Kamizono
2f078aafad Migrate DidYouMean.correct_error to DidYouMean::Correctable for MissingTemplate
Follow up to #42333.
2021-07-05 15:47:07 +09:00
Petrik
0409ed57ac Clean up checks to see if DidYouMean is defined
As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
need to check if DidYouMean is defined in the test suite. We still need
to check if the DidYouMean modules are defined in the actual code, as
someone might run Rails with DidYouMean disabled by using the
`--disable-did_you_mean` flag. This is ussually done for performance
reasons.

This commit also includes some of the changes made by Yuki in:
https://github.com/rails/rails/pull/39555
These changes include replacing Jaro with the more accurate
SpellChecker, and using DidYouMean::Correctable for simplere
corrections.

The DidYouMean::SpellChecker does have a treshold for corrections.
If there is not enough similarity it might not return a suggestion.
To stop the tests from failing some test data had to be changed.

For example, `non_existent` does not meet the treshold for `hello`, but
`ello` does:

DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
=> []
DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
=> ["hello"]

The treshold makes sense for spelling errors. But maybe we should add a
different SpellChecker that helps to get a suggestion even if there is
little overlap. For example for when a model only has 2 attributes
(title and body), it's helpful to get a suggestion for `name`

Co-Authored-By: Yuki Nishijima <yk.nishijima@gmail.com>
2021-07-04 13:43:50 +02:00
Ryuta Kamizono
91593af849 Merge pull request #41559 from jonathanhefner/sms_to-country_code
Add :country_code option to sms_to
2021-07-03 11:19:20 +09:00
Ryuta Kamizono
d7fce6c996 Fix odd closing parenthesis by enabling the Layout/ClosingParenthesisIndentation cop 2021-07-02 18:01:50 +09:00
Dirkjan Bussink
0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02:00
John Hawthorn
eeea496d5f Remove cvar for registered details 2021-06-29 15:46:18 -07:00
Michael Bianco
9508b4b3c3 Adding docs link to ujs readme 2021-06-28 14:55:37 -06:00
Zachary Scott
70a0a766e3 Remove docs for render layout: with a block and args
This behavior was removed in 9f5cd01 but these docs were missed.

Fixes #42540
2021-06-27 21:31:31 +09:00
Vasiliy Ermolovich
c69f6b1bc7 Make AssetTagHelper#preload_link_tag to use path_to_asset method instead of asset_path.
To avoid conflicts with an asset_path named route.

Closes https://github.com/rails/rails/issues/42545
2021-06-23 18:55:14 +03:00
Rafael França
58ed26f616
Revert "Extract methods assert_queries and assert_no_queries" 2021-06-17 13:35:25 -04:00
Zachary Scott
f8e45f9c6b
Merge pull request #42485 from AdityaBhutani/correct-all-x-based-occurances
[ci skip] Fixing all <x> based occurances to <x>-based
2021-06-17 08:33:54 +09:00
Aditya Bhutani
32af6add67 [ci skip] Fixing all <x> based occurances to <x>-based 2021-06-16 19:15:12 +05:30
David Heinemeier Hansson
8de181dac6
Don't attach UJS form submission handlers to Turbo forms (#42476)
* Don't attach UJS form submission handlers to Turbo forms

Allows for easier migration of apps written for UJS, such that new work can be done with Turbo forms that are marked with data-turbo=true.

* Fix duplicate selectors

* Proper fix take 2
2021-06-15 17:31:33 +02:00
Ricardo Díaz
f644f7d35b Extract methods assert_queries and assert_no_queries
Both methods are defined in multiple parts of the framework. It would
be useful to put them in a proper place, so that repetition is
avoided.

I chose the implementation from `ActiveRecord` because it's a bit more
complete with the `SQLCounter` class, and also because other parts
depend on it.
2021-06-14 09:55:13 -05:00
Rafael Mendonça França
600ff9abfc
Fix all rubocop violations 2021-06-08 23:35:59 +00:00
Adam Hess
e8156a2788 Return "test" as the controller_name in ActionView tests
before https://github.com/rails/rails/pull/40125 test names would be
set to "test" after this change controller_name was nil when using
ActionView::TestCase.

This returns ActionView::TestCase to previous behavior returning "test"
2021-06-07 15:52:08 -07:00
Simon Fish
fe5ef4281f
Add option to strip trailing newlines from ERB templates
Add failing test for views with trailing newlines

Add and test config option

Move config option to config/application.rb

Move implementation to ERB template handler

Move config option to ActionView::Template::Handlers::ERB
2021-06-04 10:27:55 +01:00
John Hawthorn
f303eb2895 Add failing test for link_tags when streaming 2021-05-31 16:13:25 -07:00
John Hawthorn
0f3a895ee1 Dont send preload links headers if streaming
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2021-05-31 16:13:25 -07:00
John Hawthorn
13327e0bec
Merge pull request #42210 from jhawthorn/template_details_rebase
Encapsulate "details" into TemplateDetails
2021-05-12 15:53:04 -07:00
Keeran Raj Hawoldar
63c32e9eda ensure normalize_name is operating on a string 2021-05-12 18:26:03 +01:00
John Hawthorn
f8f9a085cc Encapsulate "details" into TemplateDetails
When dealing with the "details" for a template: locale, format,
variant, and handler, previously we would store these in an ad-hoc way
every place we did. Often as a hash or as separate instance variables on
a class.

This PR attempts to simplify this by encapsulating known details on a
template in a new ActionView::TemplateDetails class, and requested
details in ActionView::TemplateDetails::Requested.

This allowed extracting and simplifying filtering and sorting logic from
the Resolver class as well as extracting default format logic from
UnboundTemplate.

As well as reducing complexity, in the future this should make it
possible to provide suggestions on missing template errors due to
mismatched details, and might allow improved performance.

At least for now these new classes are private (:nodoc)

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2021-05-11 18:48:24 -07:00
Ryuta Kamizono
f55010a179 select! and reject! doesn't return self unless any elements are matched
https://docs.ruby-lang.org/en/3.0.0/Array.html#method-i-select-21
https://docs.ruby-lang.org/en/3.0.0/Array.html#method-i-reject-21
2021-05-12 06:49:49 +09:00
Ryuta Kamizono
b77ae45d29 Add missing slash to test_parse_root_partial_with_slash 2021-05-12 06:24:08 +09:00
Ryuta Kamizono
6c864fa725 Remove duplicated test_parse_partial
https://buildkite.com/rails/rails/builds/77358#27d13623-5ea6-4db8-a16c-2a2ceb6a0caa/977-979
2021-05-12 06:17:43 +09:00
John Hawthorn
88b18d7f7e
Merge pull request #42195 from jhawthorn/template_path
Extract ActionView::Resolver::Path into ActionView::TemplatePath
2021-05-11 13:14:01 -07:00
John Hawthorn
f441e433d4 Appease rubocop
Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2021-05-11 10:15:24 -07:00
John Hawthorn
8d01462c85
Merge pull request #42194 from jhawthorn/optimize_normalize_name
Optimize normalize_name
2021-05-11 10:11:40 -07:00
Jean Boussier
a939c53990 Avoid sending preload links for data: URLs 2021-05-11 09:29:40 +02:00
John Hawthorn
ddb1ec2647 Improve docs for TemplatePath 2021-05-10 22:26:14 -07:00
John Hawthorn
54f8d0b269 Use TemplatePath in Digestor 2021-05-10 22:26:14 -07:00
John Hawthorn
ef2cb32090 Return TemplatePaths from all_template_paths 2021-05-10 22:26:13 -07:00
John Hawthorn
b6b1b6b27f Implement TemplatePath.parse 2021-05-10 22:26:13 -07:00
John Hawthorn
9ec086311a Extract ActionView::TemplatePath 2021-05-10 22:26:13 -07:00
John Hawthorn
5955a0a3f3 Optimize normalize_name
This is called on every render or template lookup.

    lookup_context = ActionController::Base.new.lookup_context
    normalize = lookup_context.method(:normalize_name)

    Benchmark.ips do |x|
      x.report "already normalized" do
        normalize.call("show", ["users"])
      end

      x.report "without prefixes" do
        normalize.call("users/show", [])
      end

      x.report "with prefixes in both arguments" do
        normalize.call("extra/show", ["users", "application"])
      end
    end

Before:

      already normalized      2.322M (± 0.5%) i/s -     11.615M in   5.003512s
        without prefixes      1.613M (± 0.7%) i/s -      8.076M in   5.007165s
    with prefixes in both arguments
                              1.020M (± 0.7%) i/s -      5.154M in   5.054101s

After:

      already normalized      3.740M (± 0.3%) i/s -     18.715M in   5.003477s
        without prefixes      2.197M (± 0.6%) i/s -     11.089M in   5.047800s
    with prefixes in both arguments
                              1.244M (± 0.9%) i/s -      6.246M in   5.020968s
2021-05-10 16:13:37 -07:00
Étienne Barrié
f55f923a5f Restore implicit to_s for content_for and provide 2021-05-07 12:14:39 -04:00
Aaron Patterson
908d7bc1bf
Merge branch 'main-sec'
* main-sec:
  Prevent slow regex when parsing host authorization header
  Escape allow list hosts correctly
  Prevent string polymorphic route arguments
  Prevent catastrophic backtracking during mime parsing
2021-05-05 09:03:28 -07:00
John Bampton
90b8ad5256 Fix spelling in CoffeeScript and JavaScript files [ci skip] 2021-05-05 11:08:33 +10:00
Zachary Scott
869532ccea
Merge pull request #41276 from RobinDaugherty/form_with-local-doc
Improve documentation of FormHelper#form_with `local` option [ci skip]
2021-05-05 07:16:32 +09:00
Gannon McGibbon
c4c21a9f8d
Prevent string polymorphic route arguments
url_for supports building polymorphic URLs via an array
of arguments (usually symbols and records). If an array is passed,
strings can result in unwanted route helper calls.

CVE-2021-22885
2021-05-04 13:56:37 -07:00
John Bampton
6e85b6b86e Add spell checking with codespell as a GitHub Action
`codespell` works with a small custom dictionary and seems to find perhaps more spelling mistakes than `misspell` which really only fixes commonly misspelled English words.

Not all spell checkers can check all file types and most spell checkers can't find all the errors.

https://github.com/codespell-project/codespell
https://pypi.org/project/codespell/
2021-05-04 14:46:21 +10:00
John Bampton
6d649531b9 Fix case of GitHub, JavaScript, TypeScript [ci skip] 2021-05-04 02:02:42 +10:00
Jean Boussier
147f207a57 Deprecate implicitly coercing objects to string in ActiveSupport::SafeBuffer 2021-05-03 14:16:03 +02:00
Jean Boussier
08e3e663ca
Merge pull request #42056 from Shopify/split-link-headers
Make sure not to generate Link headers longer than 8kiB
2021-05-01 17:43:58 +02:00
Jonathan Hefner
dd884eb425 Pass default values for translate through I18n
A default value can be a string that needs interpolation, Hash that
needs resolution via the `:count` option, or a Proc that needs
evaluation.  Therefore, pass default values through `I18n.translate` to
handle these cases.

Fixes #26032.
Fixes #41277.
Fixes #41380.
2021-04-30 09:25:41 -05:00
Abhay Nikam
2005afbe04 Adds option extname to stylesheet_link_tag to exclude automatically appended .css extension.
Fixes: #41918

This PR adds the option `extname` to `stylesheet_link_tag`.
Previously, `stylesheet_link_tag` automatically added `.css`.
2021-04-29 11:20:14 +05:30
John Hawthorn
e2781c2d93 Use filter_map for template_glob 2021-04-28 16:05:32 -07:00
John Hawthorn
7faa50cb32 Extract and optimize virtual path building
Before:  build      1.759M (± 0.4%) i/s -      8.855M in   5.034065s
After:   build      2.700M (± 0.8%) i/s -     13.584M in   5.031691s
2021-04-28 15:14:49 -07:00
Jean Boussier
2cb25ab35d Make sure not to generate Link headers longer than 8kiB 2021-04-27 09:41:46 +02:00
Hartley McGuire
a3e5e8d909 use ruby 2.7's filter_map instead of select + map
Related: c3d7794, bbbc861
2021-04-26 17:55:33 -04:00