Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix marshal with autoloading for nested class/module #24345

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/core_ext/marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module MarshalWithAutoloading # :nodoc:
def load(source)
super(source)
rescue ArgumentError, NameError => exc
if exc.message.match(%r|undefined class/module (.+)|)
if exc.message.match(%r|undefined class/module (.+?)(::)?\z|)
# try loading the class/module
loaded = $1.constantize

Expand Down
21 changes: 18 additions & 3 deletions activesupport/test/core_ext/marshal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def teardown
ActiveSupport::Dependencies.clear

with_autoloading_fixtures do
assert_kind_of EM, Marshal.load(dumped)
object = nil
assert_nothing_raised do
object = Marshal.load(dumped)
end

assert_kind_of EM, object
end
end

Expand All @@ -43,7 +48,12 @@ def teardown
ActiveSupport::Dependencies.clear

with_autoloading_fixtures do
assert_kind_of ClassFolder::ClassFolderSubclass, Marshal.load(dumped)
object = nil
assert_nothing_raised do
object = Marshal.load(dumped)
end

assert_kind_of ClassFolder::ClassFolderSubclass, object
end
end

Expand Down Expand Up @@ -128,7 +138,12 @@ class SomeClass
ActiveSupport::Dependencies.clear

with_autoloading_fixtures do
assert_kind_of EM, Marshal.load(f)
object = nil
assert_nothing_raised do
object = Marshal.load(f)
end

assert_kind_of EM, object
end
end
end
Expand Down