Skip to content

Commit e0b1635

Browse files
committed
FIX: to-real-file not working correctly with Unicode paths on Posix
resolves: Oldes/Rebol-issues#2599
1 parent a2ec872 commit e0b1635

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/core/n-io.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,18 @@ static REBSER *Read_All_File(char *fname)
504504
if (!tmp) return R_NONE;
505505

506506
// Convert OS native wide string back to Rebol file type
507-
new = To_REBOL_Path(tmp, 0, OS_WIDE, FALSE);
507+
if (OS_WIDE) {
508+
new = To_REBOL_Path(tmp, 0, OS_WIDE, FALSE);
509+
} else {
510+
REBLEN len = LEN_BYTES(tmp);
511+
if (Is_Not_ASCII(tmp, len)) {
512+
// Result from the native call contains Unicode chars...
513+
new = Decode_UTF_String(tmp, len, 8, FALSE, FALSE);
514+
new = To_REBOL_Path(SERIES_DATA(new), SERIES_TAIL(new), -1, FALSE);
515+
} else {
516+
new = To_REBOL_Path(tmp, len, 0, FALSE);
517+
}
518+
}
508519
if (!new) return R_NONE;
509520

510521
Set_Series(REB_FILE, D_RET, new);

src/tests/units/file-test.r3

+13
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ if find [Linux macOS] system/platform [
9696

9797

9898
===start-group=== "to-real-file"
99+
--test-- "On file"
100+
write file: %jesterka ""
101+
full: join what-dir file
102+
--assert equal? full to-real-file file
103+
--assert equal? full to-real-file join %./ file
104+
delete file
105+
--test-- "On file with Unicode chars"
106+
;@@ https://github.com/Oldes/Rebol-issues/issues/2599
107+
write file: %jěštěrka ""
108+
full: join what-dir file
109+
--assert equal? full to-real-file file
110+
--assert equal? full to-real-file join %./ file
111+
delete file
99112
--test-- "On directory"
100113
;@@ https://github.com/Oldes/Rebol-issues/issues/2600
101114
--assert equal? what-dir to-real-file %.

0 commit comments

Comments
 (0)