Commit Graph

18 Commits

Author SHA1 Message Date
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
Kir Shatrov dfcc766163 Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
Akira Matsuda 03925dc26a normalize_path used to be nil tolerant
fixes a regression introduced at 8607c25ba7
2017-07-12 19:48:31 +09:00
Koichi ITO d2901bd517 [Action Pack] `rubocop -a --only Layout/EmptyLineAfterMagicComment` 2017-07-11 13:12:32 +09:00
Kir Shatrov b3f3d49fd6 Prepare AP and AR to be frozen string friendly 2017-07-06 21:30:43 +03:00
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
eileencodes 8607c25ba7 Maintain original encoding from path
When the path info is read from the socket it's encoded as ASCII 8BIT.
The unescape method changes the encoding to UTF8 but it should maintain
the encoding of the string that's passed in.

This causes parameters to be force encoded to UTF8 when we don't
actually know what the encoding of the parameter should be.
2017-05-12 14:14:01 -04:00
Xavier Noria 35b3de8021 applies new string literal convention in actionpack/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:54:50 +02: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
Karl Entwistle 8a29713134 Force encoding of US-ASCII to UTF-8 in unescape_uri.
Because URI paths may contain non US-ASCII characters we need to force
the encoding of any unescaped URIs to UTF-8 if they are US-ASCII.
This essentially replicates the functionality of the monkey patch to
URI.parser.unescape in active_support/core_ext/uri.rb.

Fixes #16104.
2014-07-10 10:02:11 +01:00
Aaron Patterson 5682596db7 Strexp#names is only used in a test, so rm 2014-05-29 15:31:45 -07:00
Aaron Patterson 15ffbedf3b add an alternate constructor to Strexp that takes a string 2014-05-29 15:23:30 -07:00
Andrew White 5460591f02 Make URL escaping more consistent
1. Escape '%' characters in URLs - only unescaped data
   should be passed to URL helpers

2. Add an `escape_segment` helper to `Router::Utils`
   that escapes '/' characters

3. Use `escape_segment` rather than `escape_fragment`
   in optimized URL generation

4. Use `escape_segment` rather than `escape_path`
   in URL generation

For point 4 there are two exceptions. Firstly, when a route uses wildcard
segments (e.g. *foo) then we use `escape_path` as the value may contain '/'
characters. This means that wildcard routes can't be optimized. Secondly,
if a `:controller` segment is used in the path then this uses `escape_path`
as the controller may be namespaced.

Fixes #14629, #14636 and #14070.
2014-04-20 10:11:38 +01:00
edogawaconan e2ef83f838 Always escape string passed to url helper.
Makes it clear that anything passed with the helper must not be percent encoded.

Fixes previous behavior which tricks people into believing passing
non-percent-encoded will generate a proper percent-encoded path while in
reality it doesn't ('%' isn't escaped).

The intention is nice but the heuristic is broken.
2014-04-20 10:11:37 +01:00
Josh Symonds cb81a535e0 Correct error in Utils.normalize_path that changed paths improperly 2013-10-23 16:44:23 -05:00
Rafael Mendonça França dc8091b88f Use ActiveSupport::TestCase in the journey tests 2012-12-31 14:40:43 -03:00
Andrew White 56fee39c39 Integrate Journey into Action Dispatch
Move the Journey code underneath the ActionDispatch namespace so
that we don't pollute the global namespace with names that may
be used for models.

Fixes rails/journey#49.
2012-12-19 22:13:08 +00:00