Skip to content

Commit

Permalink
[fix] dont mutate module names (#5231)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek authored and kares committed Jun 26, 2018
1 parent 4e8bb26 commit a7c5eb9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -2367,9 +2367,10 @@ public RubyFixnum hash() {
@JRubyMethod(name = "to_s", alias = "inspect")
@Override
public RubyString to_s() {
Ruby runtime = getRuntime();
if(isSingleton()){
IRubyObject attached = ((MetaClass) this).getAttached();
RubyString buffer = getRuntime().newString("#<Class:");
RubyString buffer = runtime.newString("#<Class:");

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

return buffer;
}

return rubyName();
return rubyName().strDup(runtime);
}

/** rb_mod_eqq
Expand Down
9 changes: 9 additions & 0 deletions test/jruby/test_module.rb
Expand Up @@ -9,6 +9,15 @@ def test_prepend_features_type_error
Module.new.instance_eval { prepend_features(1) }
end
end

module XXX
end

def test_module_name_is_not_mutated
assert_false XXX.to_s.object_id != XXX.to_s.object_id
XXX.to_s.downcase!
assert_equal XXX.to_s, "XXX"
end

module M
C = 'public'; public_constant :C
Expand Down

0 comments on commit a7c5eb9

Please sign in to comment.