1. 23 7月, 2019 1 次提交
    • A
      Omit marshal_dump & _dump from delegate_missing_to · 056414eb
      Aaron Lipman 提交于
      Exclude missing marshal_dump and _dump methods from being delegated to
      an object's delegation target via the delegate_missing_to extension.
      This avoids unintentionally adding instance variables to an object
      during marshallization, should the delegation target be a method which
      would otherwise add them.
      
      In current versions of Ruby, a bug exists in the way objects are
      marshalled, allowing for instance variables to be added or removed
      during marshallization (see https://bugs.ruby-lang.org/issues/15968).
      This results in a corrupted serialized byte stream, causing an object's
      instance variables to "leak" into subsequent serialized objects during
      demarshallization.
      
      In Rails, this behavior may be triggered when marshalling an object that
      uses the delegate_missing_to extension, if the delegation target is a
      method which adds or removes instance variables to an object being
      marshalled - when calling Marshal.dump(object), Ruby's built in behavior
      will check whether the object responds to :marshal_dump or :_dump, which
      in turn triggers the delegation target method in the
      responds_to_missing? function defined in
      activesupport/lib/active_support/core_ext/module/delegation.rb
      
      While future versions of Ruby will resolve this bug by raising a
      RuntimeError, the underlying cause of this error may not be readily
      apparent when encountered by Rails developers. By excluding marshal_dump
      and _dump from being delegated to an object's target, this commit
      eliminates a potential cause of unexpected behavior and/or
      RuntimeErrors.
      
      Fixes #36522
      056414eb
  2. 28 2月, 2018 1 次提交
  3. 27 2月, 2018 1 次提交
  4. 26 1月, 2018 2 次提交
  5. 13 8月, 2017 1 次提交
    • A
      Test for the new exception of delegate_missing_to (#30191) · e6c310b3
      Anton Khamets 提交于
      * Add test for the new exception of delegate_missing_to
      
      * Add a changelog entry
      
      * Only check for nil if NoMethodError was raised
      
      * Make method private
      
      * Have to pass both target name and value
      
      * Inline the re-raise
      
      [Rafael Mendonça França + Anton Khamets]
      e6c310b3
  6. 11 7月, 2017 1 次提交
  7. 09 7月, 2017 1 次提交
  8. 05 7月, 2017 2 次提交
  9. 02 7月, 2017 1 次提交
  10. 01 7月, 2017 1 次提交
  11. 05 5月, 2017 1 次提交
  12. 09 4月, 2017 2 次提交
  13. 18 1月, 2017 1 次提交
  14. 13 1月, 2017 2 次提交
  15. 26 12月, 2016 1 次提交
  16. 14 11月, 2016 2 次提交
  17. 29 10月, 2016 1 次提交
  18. 16 8月, 2016 1 次提交
  19. 07 8月, 2016 4 次提交
  20. 27 5月, 2016 1 次提交
  21. 25 5月, 2016 2 次提交
  22. 02 3月, 2016 1 次提交
  23. 01 3月, 2016 1 次提交
  24. 28 2月, 2016 1 次提交
    • G
      Introduce Module#delegate_missing_to · 335fcc21
      Genadi Samokovarov 提交于
      When building decorators, a common pattern may emerge:
      
          class Partition
            def initialize(first_event)
              @events = [ first_event ]
            end
      
            def people
              if @events.first.detail.people.any?
                @events.collect { |e| Array(e.detail.people) }.flatten.uniq
              else
                @events.collect(&:creator).uniq
              end
            end
      
            private
              def respond_to_missing?(name, include_private = false)
                @events.respond_to?(name, include_private)
              end
      
              def method_missing(method, *args, &block)
                @events.send(method, *args, &block)
              end
          end
      
      With `Module#delegate_missing_to`, the above is condensed to:
      
          class Partition
            delegate_missing_to :@events
      
            def initialize(first_event)
              @events = [ first_event ]
            end
      
            def people
              if @events.first.detail.people.any?
                @events.collect { |e| Array(e.detail.people) }.flatten.uniq
              else
                @events.collect(&:creator).uniq
              end
            end
          end
      
      David suggested it in #23824.
      335fcc21
  25. 20 8月, 2015 1 次提交
  26. 23 3月, 2015 1 次提交
  27. 12 2月, 2015 1 次提交
  28. 19 9月, 2014 1 次提交
  29. 20 5月, 2014 1 次提交
  30. 17 1月, 2014 2 次提交