Skip to content

Commit

Permalink
FIX: to-real-file not working correctly with Unicode paths on Posix
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jun 3, 2024
1 parent a2ec872 commit e0b1635
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/n-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,18 @@ static REBSER *Read_All_File(char *fname)
if (!tmp) return R_NONE;

// Convert OS native wide string back to Rebol file type
new = To_REBOL_Path(tmp, 0, OS_WIDE, FALSE);
if (OS_WIDE) {
new = To_REBOL_Path(tmp, 0, OS_WIDE, FALSE);
} else {
REBLEN len = LEN_BYTES(tmp);
if (Is_Not_ASCII(tmp, len)) {
// Result from the native call contains Unicode chars...
new = Decode_UTF_String(tmp, len, 8, FALSE, FALSE);
new = To_REBOL_Path(SERIES_DATA(new), SERIES_TAIL(new), -1, FALSE);
} else {
new = To_REBOL_Path(tmp, len, 0, FALSE);
}
}
if (!new) return R_NONE;

Set_Series(REB_FILE, D_RET, new);
Expand Down
13 changes: 13 additions & 0 deletions src/tests/units/file-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ if find [Linux macOS] system/platform [


===start-group=== "to-real-file"
--test-- "On file"
write file: %jesterka ""
full: join what-dir file
--assert equal? full to-real-file file
--assert equal? full to-real-file join %./ file
delete file
--test-- "On file with Unicode chars"
;@@ https://github.com/Oldes/Rebol-issues/issues/2599
write file: %jěštěrka ""
full: join what-dir file
--assert equal? full to-real-file file
--assert equal? full to-real-file join %./ file
delete file
--test-- "On directory"
;@@ https://github.com/Oldes/Rebol-issues/issues/2600
--assert equal? what-dir to-real-file %.
Expand Down

0 comments on commit e0b1635

Please sign in to comment.