Skip to content

Commit 51ace55

Browse files
authored
Merge pull request jruby#9240 from evaniainbrooks/9120-incompat-encoding
Fix for File.path doesn't raise Encoding::CompatibilityError for ASCII incompatible string
2 parents 146ac6a + af3ee15 commit 51ace55

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

core/src/main/java/org/jruby/RubyFile.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ public static String getAdjustedPath(ThreadContext context, IRubyObject fileOrPa
13651365

13661366
// mri: FilePathValue/rb_get_path/rb_get_patch_check
13671367
public static RubyString get_path(ThreadContext context, IRubyObject path) {
1368-
if (path instanceof RubyString) return checkEmbeddedNulls(context, path);
1368+
if (path instanceof RubyString) return filePathConvert(context, (RubyString) path);
13691369

13701370
FileSites sites = sites(context);
13711371
if (sites.respond_to_to_path.respondsTo(context, path, path, true)) path = sites.to_path.call(context, path, path);
@@ -1378,6 +1378,10 @@ public static RubyString get_path(ThreadContext context, IRubyObject path) {
13781378
protected static RubyString filePathConvert(ThreadContext context, RubyString path) {
13791379
checkEmbeddedNulls(context, path);
13801380

1381+
if (!path.getEncoding().isAsciiCompatible()) {
1382+
throw context.runtime.newEncodingCompatibilityError("path name must be ASCII-compatible (" + path.getEncoding() + "): " + path);
1383+
}
1384+
13811385
if (!Platform.IS_WINDOWS) {
13821386
var encodingService = encodingService(context);
13831387
Encoding pathEncoding = path.getEncoding();
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
fails:File#path preserves the encoding of the path
2-
fails:File.path raises Encoding::CompatibilityError for ASCII-incompatible string argument
3-
fails:File.path raises Encoding::CompatibilityError when #to_path result is ASCII-incompatible

0 commit comments

Comments
 (0)