1. 07 8月, 2016 4 次提交
  2. 06 8月, 2016 1 次提交
    • E
      Fix GET JSON integration test request to use method override · af1680f5
      eileencodes 提交于
      When a `GET` request is sent `as: :json` in an integration test the test
      should use Rack's method override to change to a post request so the
      paramters are included in the postdata. Otherwise it will not encode the
      parameters correctly for the integration test.
      
      Because integration test sets up it's own middleware,
      `Rack::MethodOverride` needs to be included in the integration tests as
      well.
      
      `headers ||= {}` was moved so that headers are never nil. They should
      default to a hash.
      
      Fixes #26033
      
      [Eileen M. Uchitelle & Aaron Patterson]
      af1680f5
  3. 02 8月, 2016 6 次提交
    • K
      Fix wrong assignment. · 70b995a7
      Kasper Timm Hansen 提交于
      Screwed up both the left and right hand sides!
      70b995a7
    • K
      Set `always_permitted_parameters`. · 1d542e47
      Kasper Timm Hansen 提交于
      The tests were written with the common false value seen in Rails apps,
      show that intent in the code.
      
      Should also fix the build on 5-0-stable.
      1d542e47
    • K
      Move the YAML hook closer to `init_with`. · b71732c8
      Kasper Timm Hansen 提交于
      Looked odd, so completely detached from the other necessary part of
      the implementation.
      b71732c8
    • K
      Replace implicit formats with a case statement. · 0e0cff0f
      Kasper Timm Hansen 提交于
      The coder that Psych passes in has a `tag` method we can use to detect
      which serialization format we're reviving for. Use it and make it clearer
      alongside the `load_tags` fiddling.
      0e0cff0f
    • K
      Let Psych 2.0.9+ deserialize 2.0.8 serialized parameters. · 6eb97823
      Kasper Timm Hansen 提交于
      If we were to serialize an `ActionController::Parameters` on Psych 2.0.8, we'd get:
      
      ```yaml
      --- !ruby/hash:ActionController::Parameters
      key: :value
      ```
      
      Because 2.0.8 didn't store instance variables, while 2.0.9 did:
      https://github.com/tenderlove/psych/commit/8f84ad0fc711a82a1040def861cb121e8985fd4c
      
      That, coupled with 2.0.8 calling `new` instead of `allocate` meant parameters was
      deserialized just fine:
      https://github.com/tenderlove/psych/commit/af308f8307899cb9e1c0fffea4bce3110a1c3926
      
      However, if users have 2.0.8 serialized parameters, then upgrade to Psych 2.0.9+ and
      Rails 5, it would start to blow up because `initialize` will never be called, and thus
      `@parameters` will never be assigned. Hello, `NoMethodErrors` on `NilClass`! :)
      
      To fix this we register another variant of the previous serialization format and take
      it into account in `init_with`.
      
      I've tested this in our app and previously raising code now deserializes like a champ.
      I'm unsure how to test this in our suite because we use Psych 2.0.8 and don't know how
      to make us use 2.0.9+ for just one test.
      6eb97823
    • K
      Make Parameters support legacy YAML encodings. · 31448f2b
      Kasper Timm Hansen 提交于
      By changing ActionController::Parameter's superclass, Rails 5 also changed
      the YAML serialization format.
      
      Since YAML doesn't know how to handle parameters it would fallback to its
      routine for the superclass, which in Rails 4.2 was Hash while just Object
      in Rails 5. As evident in the tags YAML would spit out:
      
      4.2: !ruby/hash-with-ivars:ActionController::Parameters
      5.0: !ruby/object:ActionController::Parameters
      
      Thus when loading parameters YAML from 4.2 in Rails 5, it would parse a
      hash dump as it would an Object class.
      
      To fix this we have to provide our own `init_with` to be aware of the past
      format as well as the new one. Then we add a `load_tags` mapping, such that
      when the YAML parser sees `!ruby/hash-with-ivars:ActionController::Parameters`,
      it knows to call our `init_with` function and not try to instantiate it as
      a normal hash subclass.
      31448f2b
  4. 29 7月, 2016 1 次提交
  5. 28 7月, 2016 1 次提交
    • N
      Reset rack.input when the environment is scrubbed for the next request · 40758347
      Nick Sieger 提交于
      Before this change, posted parameters would leak across requests. The included
      test case failed like so:
      
            1) Failure:
          TestCaseTest#test_multiple_mixed_method_process_should_scrub_rack_input:
          --- expected
          +++ actual
          @@ -1 +1 @@
          -{"bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params"}
          +{"foo"=>"an foo", "bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params"}
      
      An argument could be made that this situation isn't encountered often and that
      one should limit the number of requests per test case, but I still think the
      parameter leaking is an unexpected side-effect.
      40758347
  6. 27 7月, 2016 4 次提交
  7. 25 7月, 2016 1 次提交
  8. 22 7月, 2016 1 次提交
    • C
      Fix 'defaults' option for root route · 31fbbb7f
      Chris Arcand 提交于
      The merging of the 'defaults' option was moved up the stack in e852daa6
      This allows us to see where these options originate from the standard
      HttpHelpers (get, post, patch, put, delete)
      
      Unfortunately this move didn't incorporate the 'root' method, which has
      always allowed the same 'defaults' option before.
      31fbbb7f
  9. 21 7月, 2016 2 次提交
  10. 17 7月, 2016 4 次提交
  11. 14 7月, 2016 3 次提交
    • G
      Check `request.path_parameters` encoding at the point they're set · 9f38a3fb
      Grey Baker 提交于
      Check for any non-UTF8 characters in path parameters at the point they're
      set in `env`. Previously they were checked for when used to get a controller
      class, but this meant routes that went directly to a Rack app, or skipped
      controller instantiation for some other reason, had to defend against
      non-UTF8 characters themselves.
      9f38a3fb
    • J
    • G
      Don't raise ActionController::UnknownHttpMethod from ActionDispatch::Static · 25c14617
      Grey Baker 提交于
      The `ActionDispatch::Static` middleware is used low down in the stack to serve
      static assets before doing much processing. Since it's called from so low in
      the stack, we don't have access to the request ID at this point, and generally
      won't have any exception handling defined (by default `ShowExceptions` is added
      to the stack quite a bit higher and relies on logging and request ID).
      
      Before https://github.com/rails/rails/commit/8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3
      this middleware would ignore unknown HTTP methods, and an exception about these
      would be raised higher in the stack. After that commit, however, that exception
      will be raised here.
      
      If we want to keep `ActionDispatch::Static` so low in the stack (I think we do)
      we should suppress the `ActionController::UnknownHttpMethod` exception here,
      and instead let it be raised higher up the stack, once we've had a chance to
      define exception handling behaviour.
      
      This PR updates `ActionDispatch::Static` so it passes `Rack::Request` objects to
      `ActionDispatch::FileHandler`, which won't raise an
      `ActionController::UnknownHttpMethod` error. If an unknown method is
      passed, it should exception higher in the stack instead, once we've had a
      chance to define exception handling behaviour.`
      25c14617
  12. 12 7月, 2016 2 次提交
  13. 11 7月, 2016 2 次提交
    • J
      Remove unused activerecord requirement in actionpack. · acf99bde
      Jun Aruga 提交于
      acf99bde
    • K
      Let TestResponse assign a parser. · 333670ce
      Kasper Timm Hansen 提交于
      Previously we'd only assign a response parser when a request came through
      Action Dispatch integration tests. This made calls to `parsed_body` when a TestResponse
      was manually instantiated — though own doing or perhaps from a framework — unintentionally
      blow up because no parser was set at that time.
      
      The response can lookup a parser entirely through its own ivars. Extract request encoder to
      its own file and assume that a viable content type is present at TestResponse instantiation.
      
      Since the default response parser is a no-op, making `parsed_body` equal to `body`, no
      exceptions will be thrown.
      333670ce
  14. 09 7月, 2016 2 次提交
    • M
      Add tests for 1xx, 204 and 304 responses to response_test.rb · bddf83bf
      Masaru Nomura 提交于
      In response_test.rb, we haven't had a test to make sure that
      
      1) these responses don't have a message-body as described in RFC7231[1]
      
      2) 1xx and 204 responses must not have a Content-Length header field
         as described in RFC7230-section3.3.2[2]
      
      [1] https://tools.ietf.org/html/rfc7231
      [2] https://tools.ietf.org/html/rfc7230#section-3.3.2
      
      Even though our implementation doesn't allow users to send
      a Content-Length header field in a 304 response, sending the
      header field is valid as mentioned in RFC7230-section3.3.2[2].
      So I've decided not to test whether or not a 304 response has
      the header.
      
      The citation from the section is as follows;
      ```
      A server MAY send a Content-Length header field in a 304 (Not
      Modified) response to a conditional GET request (Section 4.1 of
      [RFC7232]); a server MUST NOT send Content-Length in such a response
      unless its field-value equals the decimal number of octets that would
      have been sent in the payload body of a 200 (OK) response to the same
      request.
      ```
      bddf83bf
    • T
      Trust `Object#dup` in `ActionController::Parameters`, using `#initialize_copy`... · 96070595
      Tim Rogers 提交于
      Trust `Object#dup` in `ActionController::Parameters`, using `#initialize_copy` to manually duplicate the underlying parameters hash
      
      It looks like `ActionController::Parameters#dup` is leftover from when the class inherited from `Hash`. We can just trust `#dup`, which already copies the `@permitted` instance variable (confirmed by tests). We still define a `#initialize_copy` to make `@parameters` a copy that can be mutated without affecting the original instance.
      96070595
  15. 08 7月, 2016 1 次提交
  16. 07 7月, 2016 2 次提交
    • T
      Changes to a dupped `ActionController::Parameters` mutate the original · ba3dd5ca
      Tim Rogers 提交于
      When `ActionController::Parameters` is duplicated with `#dup`, it doesn't create a duplicate of the instance variables (e.g. `@parameters`) but rather maintains the reference (see <http://ruby-doc.org/core-2.3.1/Object.html>). Given that the parameters object is often manipulated as if it were a hash (e.g. with `#delete` and similar methods), this leads to unexpected behaviour, like the following:
      
      ```
      params = ActionController::Parameters.new(foo: "bar")
      duplicated_params = params.dup
      duplicated_params.delete(:foo)
      
      params == duplicated_params
      ```
      
      This fixes the bug by defining a private `#initialize_copy` method, used internally by `#dup`, which makes a copy of `@parameters`.
      ba3dd5ca
    • T
      [ci skip] Correct defaults in documentation for ActionDispatch::SSL · 8a12c7c2
      Tim Rogers 提交于
      `config.ssl_options` permits configuring various options for the middleware. Default options for HSTS (specified with the `:hsts` key in the options hash) are specified in `.default_hsts_options`. The documentation did not make clear these defaults, and in one case was wrong.
      8a12c7c2
  17. 05 7月, 2016 1 次提交
    • V
      Deprecate usage of nil as route path · 1fd9cdfd
      Volmer 提交于
      In Rails 4 these kind of routes used to work:
      
      ```ruby
      scope '/*id', controller: :builds, as: :build do
        get action: :show
      end
      ```
      
      But since 1a830cbd, routes are only created for
      paths specified as strings or symbols. Implicit `nil` paths are just ignored,
      with no deprecation warnings or errors. Routes are simply not created. This come
      as a surprise for people migrating to Rails 5, since the lack of logs or errors
      makes hard to understand where the problem is.
      
      This commit introduces a deprecation warning in case of path as `nil`, while
      still allowing the route definition.
      1fd9cdfd
  18. 02 7月, 2016 2 次提交