From 040c9c689376dd7b898ea22e944646df7bd18377 Mon Sep 17 00:00:00 2001 From: Oldes Date: Wed, 27 Jan 2021 11:51:14 +0100 Subject: [PATCH] FIX: POSIX: `query` not handling correctly file names with non ASCII chars resolves: https://github.com/Oldes/Rebol-issues/issues/2442 --- src/core/p-file.c | 15 +++++++++++++++ "src/tests/units/files/\304\215e\305\241tina.txt" | 1 + src/tests/units/port-test.r3 | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 "src/tests/units/files/\304\215e\305\241tina.txt" diff --git a/src/core/p-file.c b/src/core/p-file.c index f87c32930c..2855c4b490 100644 --- a/src/core/p-file.c +++ b/src/core/p-file.c @@ -108,6 +108,13 @@ ** ***********************************************************************/ { +#if !defined(TO_WINDOWS) + // on Posix the file.path is in UTF8 format, so must be decoded bellow + REBSER *ser = BUF_UTF8; + REBINT len; + const REBYTE *path; +#endif + switch (mode) { case SYM_SIZE: if(file->file.size == MIN_I64) { @@ -123,7 +130,15 @@ Set_File_Date(file, ret); break; case SYM_NAME: +#ifdef TO_WINDOWS Set_Series(REB_FILE, ret, To_REBOL_Path(file->file.path, 0, OS_WIDE, 0)); +#else + path = cb_cast(file->file.path); + len = (REBINT)LEN_BYTES(path); + len = Decode_UTF8(UNI_HEAD(ser), path, len, 0); + if (len < 0) len = -len; // negative len means ASCII chars only + Set_Series(REB_FILE, ret, To_REBOL_Path(UNI_HEAD(ser), len, TRUE, 0)); +#endif break; default: return FALSE; diff --git "a/src/tests/units/files/\304\215e\305\241tina.txt" "b/src/tests/units/files/\304\215e\305\241tina.txt" new file mode 100644 index 0000000000..6cbfdabcef --- /dev/null +++ "b/src/tests/units/files/\304\215e\305\241tina.txt" @@ -0,0 +1 @@ +Čeština je flektivní jazyk vyznačující se komplikovaným systémem skloňování a časování a velmi volným slovosledem. K písemným záznamům používá latinku doplněnou o znaky s diakritikou. \ No newline at end of file diff --git a/src/tests/units/port-test.r3 b/src/tests/units/port-test.r3 index 20c9f98911..0a9274768e 100644 --- a/src/tests/units/port-test.r3 +++ b/src/tests/units/port-test.r3 @@ -202,6 +202,11 @@ if system/platform = 'Windows [ --assert [file 51732] = query/mode file [type size] --assert [type: file size: 51732] = query/mode file [type: size:] + --test-- "query file name" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2442 + file: %units/files/čeština.txt + --assert not none? find (query/mode file 'name) file + --test-- "query file info (port)" file: open %units/files/alice29.txt.gz --assert [name size date type] = query/mode file none