Commit Graph

18 Commits

Author SHA1 Message Date
Rafael Mendonça França
d52d773946
Remove deprecated support to passing relative paths to render file: 2020-10-30 00:25:14 +00:00
John Hawthorn
c7820d8124 Introduce Template::File as new render file:
The previous behaviour of render file: was essentially the same as
render template:, except that templates can be specified as an absolute
path on the filesystem.

This makes sense for historic reasons, but now render file: is almost
exclusively used to render raw files (not .erb) like public/404.html. In
addition to complicating the code in template/resolver.rb, I think the
current behaviour is surprising to developers.

This commit deprecates the existing "lookup a template from anywhere"
behaviour and replaces it with "render this file exactly as it is on
disk". Handlers will no longer be used (it will render the same as if
the :raw handler was used), but formats (.html, .xml, etc) will still be
detected (and will default to :plain).

The existing render file: behaviour was the path through which Rails
apps were vulnerable in the recent CVE-2019-5418. Although the
vulnerability has been patched in a fully backwards-compatible way, I
think it's a strong hint that we should drop the existing
previously-vulnerable behaviour if it isn't a benefit to developers.
2019-03-27 15:51:25 -07:00
Aaron Patterson
f369b63ad6
Teach DetailsKey how to clear the template cache
This commit exposes all system wide view paths so that we can clear
their caches.
2019-02-08 16:13:03 -08:00
Aaron Patterson
f9bea6304d
Move templates to an anonymous subclass of AV::Base
Now we can throw away the subclass and the generated methods will get
GC'd too
2019-02-06 16:52:15 -08:00
Aaron Patterson
e17fe52e0e
Tighten up the AV::Base constructor
The AV::Base constructor was too complicated, and this commit tightens
up the parameters it will take.  At runtime, AV::Base is most commonly
constructed here:

  94d54fa4ab/actionview/lib/action_view/rendering.rb (L72-L74)

This provides an AV::Renderer instance, a hash of assignments, and a
controller instance.  Since this is the common case for construction, we
should remove logic from the constructor that handles other cases.  This
commit introduces special constructors for those other cases.
Interestingly, most code paths that construct AV::Base "strangely" are
tests.
2019-01-29 15:49:40 -08:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
mfo
6d3b57fe42 fix(streaming_template_renderer): I18n.locale broken in layout. I18n gem stores the current locale in Thread.current[:local] (see: https://github.com/svenfuchs/i18n/blob/master/lib/i18n.rb#L23). StreamingTemplateRenderer is implemented with Fiber which have its own stack of locals and can not access Thread.current.locals(keys, see: https://ruby-doc.org/core-2.2.0/Thread.html#class-Thread-label-Fiber-local+vs.+Thread-local). 2017-11-25 21:32:02 +01:00
Kir Shatrov
424117281e Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Matthew Draper
3420a14590 Merge pull request #29540 from kirs/rubocop-frozen-string
Enforce frozen string in Rubocop
2017-07-02 01:11:50 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Pat Allan
3d453b409d Make ActionView frozen string literal friendly.
Plus a couple of related ActionPack patches.
2017-06-20 22:20:04 +10:00
Xavier Noria
63fff600ac modernizes hash syntax in actionview 2016-08-06 19:36:34 +02:00
Xavier Noria
4b6c68dfb8 applies new string literal convention in actionview/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:50:17 +02:00
yuuji.yaginuma
35d12ef3f1 fix ActionView::Template::Error when using Streaming with capture.
can't acquire a encoding from StreamingBuffer. fixes #12001
2015-03-01 16:20:27 +09:00
Vipul A M
6eced6a1fe Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 onwards. 2015-02-03 20:51:40 +05:30
Piotr Sarnacki
5e5bf31b4a Remove unneeded files 2013-06-20 17:23:16 +02:00
Piotr Sarnacki
eb23754ebb Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00