Skip to content

Commit 254b78b

Browse files
committed
FIX: Rebol cannot run a script that has UTF-8 chars in its filename or path
fixes: zsx#48
1 parent dcd4058 commit 254b78b

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/core/b-init.c

+18-9
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,21 @@ static REBCNT Set_Option_Word(REBCHR *str, REBCNT field)
768768
return n;
769769
}
770770

771+
static void Set_Option_File(REBCNT field, REBYTE* src, REBOOL dir )
772+
{
773+
REBSER *ser;
774+
REBVAL *val;
775+
if (OS_WIDE) {
776+
ser = To_REBOL_Path(src, 0, OS_WIDE, dir);
777+
}
778+
else {
779+
ser = Decode_UTF_String(src, LEN_BYTES(src), 8, FALSE);
780+
ser = To_REBOL_Path(BIN_DATA(ser), BIN_LEN(ser), (REBOOL)!BYTE_SIZE(ser), dir);
781+
}
782+
val = Get_System(SYS_OPTIONS, field);
783+
Set_Series(REB_FILE, val, ser);
784+
}
785+
771786
/***********************************************************************
772787
**
773788
*/ static void Init_Main_Args(REBARGS *rargs)
@@ -803,22 +818,16 @@ static REBCNT Set_Option_Word(REBCHR *str, REBCNT field)
803818

804819
// Print("script: %s", rargs->script);
805820
if (rargs->script) {
806-
ser = To_REBOL_Path(rargs->script, 0, OS_WIDE, 0);
807-
val = Get_System(SYS_OPTIONS, OPTIONS_SCRIPT);
808-
Set_Series(REB_FILE, val, ser);
821+
Set_Option_File(OPTIONS_SCRIPT, (REBYTE*)rargs->script, FALSE);
809822
}
810823

811824
if (rargs->exe_path) {
812-
ser = To_REBOL_Path(rargs->exe_path, 0, OS_WIDE, 0);
813-
val = Get_System(SYS_OPTIONS, OPTIONS_BOOT);
814-
Set_Series(REB_FILE, val, ser);
825+
Set_Option_File(OPTIONS_BOOT, (REBYTE*)rargs->exe_path, FALSE);
815826
}
816827

817828
// Print("home: %s", rargs->home_dir);
818829
if (rargs->home_dir) {
819-
ser = To_REBOL_Path(rargs->home_dir, 0, OS_WIDE, TRUE);
820-
val = Get_System(SYS_OPTIONS, OPTIONS_HOME);
821-
Set_Series(REB_FILE, val, ser);
830+
Set_Option_File(OPTIONS_HOME, (REBYTE*)rargs->home_dir, TRUE);
822831
}
823832

824833
n = Set_Option_Word(rargs->boot, OPTIONS_BOOT_LEVEL);

0 commit comments

Comments
 (0)