Skip to content

Don't try to dup the String class #1038

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Next Release
============

* Your contribution here.
#### Features

#### Fixes
* [#1038](https://github.com/intridea/grape/pull/1038): Avoid dup-ing the String class when used in inherited params - [@rnubel](https://github.com/rnubel).

0.12.0 (6/18/2015)
==================
Expand Down
9 changes: 9 additions & 0 deletions lib/backports/active_support/duplicable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def duplicable?
false
end
end
class String
class << self
# Rubinius explicitly disallows this. Also, there's no real
# reason you'd want to duplicate the String class in a deep_dup.
def duplicable?
false
end
end
end
require 'bigdecimal'
# rubocop:disable Lint/HandleExceptions
class BigDecimal
Expand Down
1 change: 1 addition & 0 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
else
require_relative 'backports/active_support/deep_dup'
end
require_relative 'backports/active_support/duplicable'

require 'active_support/ordered_hash'
require 'active_support/core_ext/object/conversions'
Expand Down
7 changes: 7 additions & 0 deletions spec/grape/util/inheritable_values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ module Util
expect(subject.to_hash).to eq(some_thing: :foo, some_thing_more: :foo_bar)
end
end

describe '#clone' do
it 'clones itself even when containing a String class' do
subject[:foo] = String
expect(subject.clone.to_hash).to eq(foo: String)
end
end
end
end
end