Skip to content

Commit

Permalink
FIX: POSIX: query not handling correctly file names with non ASCII …
Browse files Browse the repository at this point in the history
…chars

resolves: Oldes/Rebol-issues#2442
  • Loading branch information
Oldes committed Jan 27, 2021
1 parent 2f20ab8 commit 040c9c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/core/p-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/tests/units/files/čeština.txt
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions src/tests/units/port-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 040c9c6

Please sign in to comment.