1. 22 9月, 2020 1 次提交
    • A
      Catch invalid UTF-8 encodings on ActionDispatch::Http::Request#POST (#40124) · 7dc53ec9
      Adrianna Chang 提交于
      * Add binary encoding logic into ActionDispatch::Request::Utils
      
      Moving the logic to set binary encoding into ActionDispatch::Request::Utils
      will allow us to encode from GET and POST in ActionDispatch::Request.
      
      * Refactor binary encoding logic
      
      - Move binary encoding calls into GET, POST and path_parameters
      - Remove binary encoding from ActionDispatch::Http::Request
      - This way, we only raise an invalid encoding exception if the controller is not requesting
      parameters in binary encoding
      
      * Check if encoding is valid in ActionDispatch::Request#POST and raise BadRequest if invalid
      
      * Fix multipart_params_test that has binary-encoded params containing invalid UTF-8 characters
      
      * Address PR comments
      
      * Pass action and controller to Request::Utils.set_binary_encoding
      
      [Rafael Mendonça França + Adrianna Chang]
      7dc53ec9
  2. 19 9月, 2020 1 次提交
  3. 16 9月, 2020 3 次提交
  4. 06 9月, 2020 2 次提交
    • P
      Shorten inspect on AbstractController::Base · 080edb44
      Petrik 提交于
      Calling self in an action of a controller generates an endless stream of
      characters, including the request object and all instances variables.
      This can be frustrating when using a debugger in a controller and
      accidentally calling `self` generates output for a couple of seconds.
      
      This shortens inspect to only show the class name.
      
          MyController.new.inspect # => "#<MyController:0x00000000005028>"
      080edb44
    • P
      Shorten inspect on ActionDispatch::Request · a610f61e
      Petrik 提交于
      Calling request in an action of a controller generates an endless stream of
      characters, including the Rack app and middlewares.
      This can be frustrating when using a debugger in a controller and
      accidentally calling `request` generates output for a couple of seconds.
      
      Inspect on ActionDispatch::Request is shortened to the most relevant
      attributes and uses the same format as used for request in the logs:
      
          "#<ActionDispatch::Request POST "https://example.com/path/of/some/uri?q=1" for 1.2.3.4>"
      a610f61e
  5. 03 9月, 2020 1 次提交
    • J
      Use unique controller per ActionView::TestCase · 65e42c91
      John Hawthorn 提交于
      Previously the same class, ActionView::TestCase::TestController, was
      used to build a controller for every ActionView::TestCase class.
      
      This caused issues when helpers/helper methods were set directly on the
      controller (which from one test we seem to want to support).
      
      This commit solves this by creating a new controller class for every
      test case, which gives the controller a unique set of helpers to work
      with.
      Co-authored-by: NJohn Crepezzi <seejohnrun@github.com>
      65e42c91
  6. 31 8月, 2020 1 次提交
  7. 26 8月, 2020 2 次提交
  8. 11 8月, 2020 2 次提交
  9. 30 7月, 2020 1 次提交
  10. 28 7月, 2020 1 次提交
    • D
      Move Path::Pattern factories into test helper · 8eec6ee9
      Daniel Colson 提交于
      `Pattern#from_sting` was introduced in bb207ea7 to support creating
      patterns from strings in tests (removing a conditional in the initialize
      method that had been there only for the sake of those tests).
      
      `Pattern#build` was introduced in 947ebe9a, and was similarly used only
      in tests.
      
      My understanding is that [`Mapping#path`][path] is the only place where
      we initialize a `Path::Pattern` in library code.
      
      Since these two methods appear to be used only in tests, this
      commit moves them out of the class and into a test helper.
      
      My reasoning for doing this is that I am doing some performance work
      that may involve a modification to how `Path::Pattern`s get initialized,
      and I will have more confidence in that work if I know for sure that
      these methods are test helpers that can be modified freely.
      
      [path]: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#L192-L194
      8eec6ee9
  11. 26 7月, 2020 1 次提交
  12. 25 7月, 2020 2 次提交
    • D
      Build symbols descending from stars with regexp · 185c4f2d
      Daniel Colson 提交于
      Before this commit we initialized all Symbols with the default regexp,
      then later on reassigned any symbols descending from stars with either
      their regexp from `@requirements` or the default greedy regexp.
      
      With this commit we initialize all Symbols descending from Stars with
      the greedy regexp at parse time. This allows us to get rid of the star
      branch in path/pattern, since any regexps from `@requirements` will
      already have been set in the symbol branch of this code.
      
      This is essentially an alternate version of #38901. Getting rid of the
      extra branch makes some performance work I am doing a bit easier, plus
      it saves us a few method calls. Also the constant saves us from creating
      the same regexp multiple times, and it is nice to give that regexp a
      name.
      185c4f2d
    • M
      Fix argument naming in `AbstractStore#set_cookie` · 9cc8e51e
      Marc Rohloff 提交于
      The signature in Rack https://github.com/rack/rack/blob/master/lib/rack/session/abstract/id.rb#L415 expects a response as the second argument
      9cc8e51e
  13. 24 7月, 2020 1 次提交
    • E
      Refactor `process` method · 5f63c771
      eileencodes 提交于
      Awhile back tenderlove and I worked to improve performance of
      integration tests and remove controller tests. The second never
      happened, we ended up soft deprecating them but never did that
      completely.
      
      Now that we're revisting that work we need a way to override these two
      methods in tests so that we can convert tests in Rails to be integration
      tests instead of controller tests. Splitting these two concerns into two
      methods allows us to overwrite them to work for our needs while
      refactoring the test harness code.
      
      These methods are private because they should not be used by an
      application or gems, they will be removed when the refactoring has been
      completed.
      Co-authored-by: NAaron Patterson <tenderlove@ruby-lang.org>
      5f63c771
  14. 23 7月, 2020 2 次提交
    • D
      Alter regexp on initialize to avoid extra ast pass · 4b01bded
      Daniel Colson 提交于
      Along the same lines as #38901, #39903, and #39914, this commit removes
      one pass through the journey ast in an attempt to improve application
      boot time.
      
      Before this commit, `Mapper#path` would iterate through the ast to alter
      the regex for custom routes. With this commit we move the regex
      alterations to initialize, where we were already iterating through the
      ast.
      
      The Benchmark for this change is similar to what we have been seeing in
      the other PRs.
      
      ```
      Warming up --------------------------------------
                     after    13.121k i/100ms
                    before     7.416k i/100ms
      Calculating -------------------------------------
                     after    128.469k (± 3.1%) i/s -    642.929k in 5.009391s
                    before     76.561k (± 1.8%) i/s -    385.632k in 5.038677s
      
      Comparison:
                     after:   128469.4 i/s
                    before:    76560.8 i/s - 1.68x  (± 0.00) slower
      
      Calculating -------------------------------------
                     after   160.000  memsize (     0.000  retained)
                               3.000  objects (     0.000  retained)
                               0.000  strings (     0.000  retained)
                    before   360.000  memsize (     0.000  retained)
                               6.000  objects (     0.000  retained)
                               0.000  strings (     0.000  retained)
      
      Comparison:
                     after:        160 allocated
                    before:        360 allocated - 2.25x more
      ```
      4b01bded
    • D
      Consolidate passes through path ast · 6a2adeb3
      Daniel Colson 提交于
      Along the same lines as https://github.com/rails/rails/pull/38901,
      this commit makes a small performance enhancement by iterating through
      the ast once instead of twice when initializing a Mapping.
      
      This stemmed from work to improve the boot time of an application with
      3500+ routes. This patch only shaves off about 70ms from our boot time,
      and about 25000 allocations, but every little bit counts!
      
      Benchmark
      ---
      
      ```rb
      
      require "bundler/inline"
      
      gemfile(true) do
        source "https://rubygems.org"
      
        git_source(:github) { |repo| "https://github.com/#{repo}.git" }
      
        # Activate the gem you are reporting the issue against.
        gem "rails", path: "/Users/daniel/Desktop/oss/rails/rails"
        gem "benchmark-ips"
        gem "benchmark-memory", require: "benchmark/memory"
      end
      
      require "action_controller/railtie"
      
      class TestApp < Rails::Application
        config.root = __dir__
        config.hosts << "example.org"
        config.session_store :cookie_store, key: "cookie_store_key"
        secrets.secret_key_base = "secret_key_base"
      
        config.logger = Logger.new($stdout)
        Rails.logger = config.logger
      
        routes.draw do
          get("/*wildcard", to: "controller#index")
        end
      end
      ```
      
      With the benchmarking code inserted into Mapper#initialize:
      
      ```rb
      after = -> {
        path_params = []
        wildcard_options = {}
        ast.each do |node|
          if node.symbol?
            path_params << node.to_sym
          elsif node.star? && formatted != false
            # Add a constraint for wildcard route to make it non-greedy and match the
            # optional format part of the route by default.
            wildcard_options[node.name.to_sym] ||= /.+?/
          end
        end
      
        wildcard_options.merge(options)
      }
      
      before = -> {
        path_params = ast.find_all(&:symbol?).map(&:to_sym)
      
        add_wildcard_options(options, formatted, ast)
      }
      
      puts "IPS"
      
      Benchmark.ips do |x|
        x.report("before") { before.call }
        x.report("after") { after.call }
        x.compare!
      end
      
      puts "MEMORY"
      
      Benchmark.memory do |x|
        x.report("before") { before.call }
        x.report("after") { after.call }
        x.compare!
      end
      ```
      
      The results are:
      
      ```
      IPS
      Warming up --------------------------------------
                    before    14.352k i/100ms
                     after    30.852k i/100ms
      Calculating -------------------------------------
                    before    135.675k (± 3.7%) i/s -    688.896k in   5.084368s
                     after    288.126k (± 3.3%) i/s -      1.450M in   5.038072s
      
      Comparison:
                     after:   288126.4 i/s
                    before:   135675.1 i/s - 2.12x  (± 0.00) slower
      
      MEMORY
      Calculating -------------------------------------
                    before   360.000  memsize (     0.000  retained)
                               7.000  objects (     0.000  retained)
                               0.000  strings (     0.000  retained)
                     after   200.000  memsize (     0.000  retained)
                               4.000  objects (     0.000  retained)
                               0.000  strings (     0.000  retained)
      
      comparison:
                     after:        200 allocated
                    before:        360 allocated - 1.80x more  end
      ```
      6a2adeb3
  15. 20 7月, 2020 2 次提交
  16. 17 7月, 2020 1 次提交
  17. 10 7月, 2020 1 次提交
  18. 06 7月, 2020 1 次提交
  19. 01 7月, 2020 1 次提交
  20. 30 6月, 2020 1 次提交
  21. 26 6月, 2020 1 次提交
  22. 19 6月, 2020 1 次提交
    • E
      Fix json encoded controller tests · 9540a7b1
      eileencodes 提交于
      The controller test case is trying to encode json parameters in the same
      way it encodes query parameters. However we need to encode json
      parameters as json.
      
      This was broken in #39534 because `generate_extras` is encoding
      everything into query parameters. But json parameters are in the post
      body and need to be treated differently than the query parameters.
      
      Followup to #39651
      
      Aaron Patterson <tenderlove@ruby-lang.org>
      9540a7b1
  23. 18 6月, 2020 1 次提交
  24. 17 6月, 2020 1 次提交
  25. 16 6月, 2020 1 次提交
    • E
      Fix route params using reserved keywords: · 7dc4c436
      Edouard CHIN 提交于
      - In #39534, `Routing::RouteSet#generate_extras` (which get called)
        by ActionController::TestCase now go through `path_for` which strips
        out all key in the options hash that have the same name as the ones
        defined in `RESERVED_OPTIONS`.
      7dc4c436
  26. 14 6月, 2020 1 次提交
  27. 11 6月, 2020 1 次提交
  28. 10 6月, 2020 2 次提交
  29. 09 6月, 2020 1 次提交
  30. 06 6月, 2020 1 次提交
    • E
      Convert route params array into object · 437ab203
      eileencodes 提交于
      This PR converts the route params array into an object and moves the
      error generation code into its own object as well. This is a refactoring
      of internal code to make it easier to change and simplier for internals
      to interface with. We have two new objects:
      
      1) `RouteWithParams`
      
      Previously `#generate` returned an array of parameterized parts for a
      route. We have now turned this into an object with a `path` and a
      `params methods` to be able to access the parts we need.
      
      2) `MissingRoute`
      
      `#generate` was also responsible for constructing the message for the
      error. We've moved this code into the new `MissingRoute` object so it
      does that work instead.
      
      This change makes these methods reusable throughout the code and easier
      for future refactoring we plan to do.
      Co-authored-by: NAaron Patterson <aaron.patterson@gmail.com>
      437ab203
  31. 04 6月, 2020 1 次提交