From 3131f5796b7b0fee9aab7c51bec205cf2fac7cc3 Mon Sep 17 00:00:00 2001 From: Jordan Raine Date: Fri, 12 May 2017 14:00:36 -0700 Subject: Safely handle modules in hierarchy Adds a check before calling `superclass` on an ancestor of a subclass of `Rack::ID` to avoid calling `superclass` on `Module`, which does not implement it. Here is an code example that causes exercises this special case: ```ruby ID = Class.new IDChild = Class.new(ID) MyMod = Module.new Foo = Class.new(IDChild) Foo.include(MyMod) Foo.ancestors.find { |kl| kl.superclass == ID } # NoMethodError: undefined method `superclass' for MyMod:Module Foo.ancestors.find { |kl| kl.respond_to?(:superclass) && kl.superclass == ID } # => IDChild ``` --- lib/rack/session/abstract/id.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rack/session/abstract/id.rb b/lib/rack/session/abstract/id.rb index d12b3b53..1bb8d5d0 100644 --- a/lib/rack/session/abstract/id.rb +++ b/lib/rack/session/abstract/id.rb @@ -408,7 +408,7 @@ module Rack class ID < Persisted def self.inherited(klass) - k = klass.ancestors.find { |kl| kl.superclass == ID } + k = klass.ancestors.find { |kl| kl.respond_to?(:superclass) && kl.superclass == ID } unless k.instance_variable_defined?(:"@_rack_warned") warn "#{klass} is inheriting from #{ID}. Inheriting from #{ID} is deprecated, please inherit from #{Persisted} instead" if $VERBOSE k.instance_variable_set(:"@_rack_warned", true) -- cgit v1.2.3-24-ge0c7