Skip to content

Commit a37df3e

Browse files
rnubeldblock
authored andcommitted
Don't try to dup the String class.
Rubinius will raise a TypeError, should you try String.dup, whereas MRI has no problem with it. As such, this change marks String as un- duplicable with respect to ActiveSupports' #duplicable? method, used by #deep_dup. Since this change isn't in upstream ActiveSupport, I also forced the backport to always be loaded (this could be changed to just a monkeypatch of the String class, though).
1 parent 7c9623e commit a37df3e

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
Next Release
22
============
33

4+
#### Features
5+
46
* Your contribution here.
57

8+
#### Fixes
9+
10+
* [#1038](https://github.com/intridea/grape/pull/1038): Avoid dup-ing the String class when used in inherited params - [@rnubel](https://github.com/rnubel).
11+
612
0.12.0 (6/18/2015)
713
==================
814

lib/backports/active_support/duplicable.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def duplicable?
7373
false
7474
end
7575
end
76+
class String
77+
class << self
78+
# Rubinius explicitly disallows this. Also, there's no real
79+
# reason you'd want to duplicate the String class in a deep_dup.
80+
def duplicable?
81+
false
82+
end
83+
end
84+
end
7685
require 'bigdecimal'
7786
# rubocop:disable Lint/HandleExceptions
7887
class BigDecimal

lib/grape.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
else
1616
require_relative 'backports/active_support/deep_dup'
1717
end
18+
require_relative 'backports/active_support/duplicable'
1819

1920
require 'active_support/ordered_hash'
2021
require 'active_support/core_ext/object/conversions'

spec/grape/util/inheritable_values_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ module Util
5858
expect(subject.to_hash).to eq(some_thing: :foo, some_thing_more: :foo_bar)
5959
end
6060
end
61+
62+
describe '#clone' do
63+
it 'clones itself even when containing a String class' do
64+
subject[:foo] = String
65+
expect(subject.clone.to_hash).to eq(foo: String)
66+
end
67+
end
6168
end
6269
end
6370
end

0 commit comments

Comments
 (0)