Skip to content

Commit c2abc8c

Browse files
ryenusheadius
authored andcommitted
jruby#6606 - respect external encoding instead of hard coding UTF-8
1 parent 6bb53c8 commit c2abc8c

5 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/org/jruby/RubyDir.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
443443
Ruby runtime = context.getRuntime();
444444
RubyString path = args.length == 1 ?
445445
RubyFile.get_path(context, args[0]) : getHomeDirectoryPath(context);
446-
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.getUnicodeValue(), null);
446+
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
447447
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
448448
JRubyFile dir = getDir(runtime, adjustedPath, true);
449449
String realPath = null;
@@ -733,7 +733,7 @@ public static IRubyObject exist(ThreadContext context, IRubyObject recv, IRubyOb
733733
// ----- Helper Methods --------------------------------------------------------
734734
protected static String getPath19(ThreadContext context, IRubyObject arg) {
735735
RubyString pathObject = arg instanceof RubyString ? (RubyString) arg : arg.callMethod(context, "to_path").convertToString();
736-
return pathObject.getUnicodeValue();
736+
return pathObject.asJavaString();
737737
}
738738

739739
/** Returns a Java <code>File</code> object for the specified path. If

src/org/jruby/RubyFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public static IRubyObject chown(ThreadContext context, IRubyObject recv, IRubyOb
585585
public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRubyObject arg) {
586586
RubyString filename = get_path(context, arg);
587587

588-
String jfilename = filename.getUnicodeValue();
588+
String jfilename = filename.asJavaString();
589589

590590
String name = jfilename.replace('\\', '/');
591591
int minPathLength = 1;
@@ -1315,7 +1315,7 @@ public static JRubyFile file(IRubyObject pathOrFile) {
13151315
return JRubyFile.create(runtime.getCurrentDirectory(), ((RubyFile) pathOrFile).getPath());
13161316
} else {
13171317
RubyString pathStr = get_path(runtime.getCurrentContext(), pathOrFile);
1318-
String path = pathStr.getUnicodeValue();
1318+
String path = pathStr.asJavaString();
13191319
String[] pathParts = splitURI(path);
13201320
if (pathParts != null && pathParts[0].equals("file:")) {
13211321
path = pathParts[1];

src/org/jruby/RubyFileTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static IRubyObject directory_p(ThreadContext context, IRubyObject filenam
9999
}
100100
JRubyFile file = file(filename);
101101

102-
return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isDirectory());
102+
return runtime.newBoolean(file.exists() && file.isDirectory());
103103
}
104104

105105
@JRubyMethod(name = "executable?", required = 1, module = true)
@@ -566,10 +566,12 @@ private static ZipEntry file_in_archive(IRubyObject path) {
566566
}
567567

568568
RubyString pathStr = get_path(runtime.getCurrentContext(), path);
569-
String pathJStr = pathStr.getUnicodeValue();
569+
String pathJStr = pathStr.asJavaString();
570+
570571
if (pathJStr.startsWith("jar:")) {
571572
pathJStr = pathJStr.substring(4);
572573
}
574+
573575
if (pathJStr.startsWith("file:")) {
574576
String file = pathJStr.substring(5);
575577
int bang = file.indexOf('!');

src/org/jruby/RubyString.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,8 @@ public RubyString(Ruby runtime, RubyClass rubyClass) {
385385
public RubyString(Ruby runtime, RubyClass rubyClass, CharSequence value) {
386386
super(runtime, rubyClass);
387387
assert value != null;
388-
byte[] bytes = RubyEncoding.encodeUTF8(value);
389-
this.value = new ByteList(bytes, false);
390-
this.value.setEncoding(UTF8);
388+
byte[] bytes = RubyEncoding.encode(value, Charset.defaultCharset());
389+
this.value = new ByteList(bytes, runtime.getDefaultExternalEncoding(), false);
391390
}
392391

393392
public RubyString(Ruby runtime, RubyClass rubyClass, byte[] value) {

src/org/jruby/javasupport/JavaUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public void set(Ruby runtime, Object array, int i, IRubyObject value) {
713713
private static final JavaConverter JAVA_STRING_CONVERTER = new JavaConverter(String.class) {
714714
public IRubyObject convert(Ruby runtime, Object object) {
715715
if (object == null) return runtime.getNil();
716-
return RubyString.newUnicodeString(runtime, (String)object);
716+
return RubyString.newString(runtime, (String)object);
717717
}
718718
public IRubyObject get(Ruby runtime, Object array, int i) {
719719
return convert(runtime, ((String[]) array)[i]);

0 commit comments

Comments
 (0)