Skip to content

Commit a7c5eb9

Browse files
ahorekkares
authored andcommittedJun 26, 2018
[fix] dont mutate module names (#5231)
1 parent 4e8bb26 commit a7c5eb9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

‎core/src/main/java/org/jruby/RubyModule.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -2367,9 +2367,10 @@ public RubyFixnum hash() {
23672367
@JRubyMethod(name = "to_s", alias = "inspect")
23682368
@Override
23692369
public RubyString to_s() {
2370+
Ruby runtime = getRuntime();
23702371
if(isSingleton()){
23712372
IRubyObject attached = ((MetaClass) this).getAttached();
2372-
RubyString buffer = getRuntime().newString("#<Class:");
2373+
RubyString buffer = runtime.newString("#<Class:");
23732374

23742375
if (attached != null) { // FIXME: figure out why we getService null sometimes
23752376
if (attached instanceof RubyClass || attached instanceof RubyModule) {
@@ -2378,12 +2379,12 @@ public RubyString to_s() {
23782379
buffer.cat19((RubyString) attached.anyToString());
23792380
}
23802381
}
2381-
buffer.cat19(getRuntime().newString(">"));
2382+
buffer.cat19(runtime.newString(">"));
23822383

23832384
return buffer;
23842385
}
23852386

2386-
return rubyName();
2387+
return rubyName().strDup(runtime);
23872388
}
23882389

23892390
/** rb_mod_eqq

‎test/jruby/test_module.rb

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ def test_prepend_features_type_error
99
Module.new.instance_eval { prepend_features(1) }
1010
end
1111
end
12+
13+
module XXX
14+
end
15+
16+
def test_module_name_is_not_mutated
17+
assert_false XXX.to_s.object_id != XXX.to_s.object_id
18+
XXX.to_s.downcase!
19+
assert_equal XXX.to_s, "XXX"
20+
end
1221

1322
module M
1423
C = 'public'; public_constant :C

0 commit comments

Comments
 (0)