Skip to content

Commit f176877

Browse files
committedJun 14, 2018
Fixes #3688. Multibyte identifiers not marshaled correctly.
This has two fixes. Missed error messages not using str() method to properly build up encoded error string. Also we should ask for rubyName vs Name so we get valid bytes. There is a mystery I added a FIXME for where I don't understand why we build up a RubyString by walking type containment then we walk that string again looking for problems. So there may be more work here? but if so we will open up a new issue for it.
1 parent c93ba6f commit f176877

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/RubyClass.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import static org.jruby.util.CodegenUtils.ci;
4141
import static org.jruby.util.CodegenUtils.p;
4242
import static org.jruby.util.CodegenUtils.sig;
43+
import static org.jruby.util.RubyStringBuilder.str;
44+
import static org.jruby.util.RubyStringBuilder.types;
4345
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
4446
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
4547
import static org.objectweb.asm.Opcodes.ACC_STATIC;
@@ -2114,7 +2116,7 @@ public IRubyObject smartLoadNewUser(IRubyObject target, IRubyObject data) {
21142116
target.callMethod(context, "marshal_load", data);
21152117
return target;
21162118
} else {
2117-
throw runtime.newTypeError("class " + getName() + " needs to have method `marshal_load'");
2119+
throw runtime.newTypeError(str(runtime, "class ", types(runtime, this), " needs to have method `marshal_load'"));
21182120
}
21192121

21202122
} else if (!(cache = searchWithCache("marshal_load")).method.isUndefined()) {
@@ -2164,7 +2166,7 @@ public IRubyObject smartLoadOldUser(IRubyObject data) {
21642166
if (method.call(context, this, getSingletonClass(), "respond_to?", runtime.newSymbol("_load")).isTrue()) {
21652167
return callMethod(context, "_load", data);
21662168
} else {
2167-
throw runtime.newTypeError("class " + getName() + " needs to have method `_load'");
2169+
throw runtime.newTypeError(str(runtime, "class ", types(runtime, this), " needs to have method `_load'"));
21682170
}
21692171

21702172
} else if (!(cache = getSingletonClass().searchWithCache("_load")).method.isUndefined()) {
@@ -2176,7 +2178,7 @@ public IRubyObject smartLoadOldUser(IRubyObject data) {
21762178
} else {
21772179

21782180
// provide an error, since it doesn't exist
2179-
throw runtime.newTypeError("class " + getName() + " needs to have method `_load'");
2181+
throw runtime.newTypeError(str(runtime, "class ", types(runtime, this), " needs to have method `_load'"));
21802182

21812183
}
21822184
}

Diff for: ‎core/src/main/java/org/jruby/runtime/marshal/MarshalStream.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void writeDirectly(IRubyObject value) throws IOException {
210210
}
211211

212212
public static String getPathFromClass(RubyModule clazz) {
213-
String path = clazz.getName();
213+
RubyString path = clazz.rubyName();
214214

215215
if (path.charAt(0) == '#') {
216216
Ruby runtime = clazz.getRuntime();
@@ -221,10 +221,14 @@ public static String getPathFromClass(RubyModule clazz) {
221221
RubyModule real = clazz.isModule() ? clazz : ((RubyClass)clazz).getRealClass();
222222
Ruby runtime = clazz.getRuntime();
223223

224-
if (runtime.getClassFromPath(path) != real) {
224+
// FIXME: This is weird why we do this. rubyName should produce something which can be referred so what example
225+
// will this fail on? If there is a failing case then passing asJavaString may be broken since it will not be
226+
// a properly encoded string. If this is an issue we should make a clazz.IdPath where all segments are returned
227+
// by their id names.
228+
if (runtime.getClassFromPath(path.asJavaString()) != real) {
225229
throw runtime.newTypeError(str(runtime, types(runtime, clazz), " can't be referred"));
226230
}
227-
return path;
231+
return path.asJavaString();
228232
}
229233

230234
private void writeObjectData(IRubyObject value) throws IOException {

0 commit comments

Comments
 (0)
Please sign in to comment.