Bug #79455 [NEW]: scandir() mishandles UTF-8 character(s)

From: Date: Tue, 07 Apr 2020 14:04:34 +0000
Subject: Bug #79455 [NEW]: scandir() mishandles UTF-8 character(s)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226464@lists.php.net to get a copy of this message
From:             pguest at meaa dot mea dot com
Operating system: Windows 10
PHP version:      7.4.4
Package:          *Directory Services problems
Bug Type:         Bug
Bug description:scandir() mishandles UTF-8 character(s)

Description:
------------
A Windows filesystem directory containing the character:
á, 225, 0xE1

is returned from scandir as two characters:
Ã, 195, 0xC3
¡, 161, 0xA1

In otherwords:
'Arquivo dos Gráficos'
becomes:
'Arquivo dos Gráficos'

Test script:
---------------
<?php

$rootdir = 'C:/temp/';
$portuguese_string = 'Arquivo dos Gráficos';
$newdir = $rootdir . $portuguese_string;
if (is_dir($newdir))
{
   rmdir ($newdir);
}
if (is_dir($rootdir))
{
   rmdir ($rootdir);
}

mkdir($rootdir);
mkdir($newdir);

echo sprintf("'%s' encoding: %s\n", $portuguese_string,
mb_detect_encoding($portuguese_string));
$scandir_return = scandir($rootdir);
echo "scandir() returns: " . print_r($scandir_return, true);
echo sprintf("'%s' encoding: %s\n", $scandir_return[2],
mb_detect_encoding($scandir_return[2]));

?>


Expected result:
----------------
The expectation is that scandir() should read back the directory string
with the same UTF-8 characters involved in its creation.

Actual result:
--------------
'Arquivo dos Gráficos'
becomes:
'Arquivo dos Gráficos'

-- 
Edit bug report at https://bugs.php.net/bug.php?id=79455&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79455&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79455&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79455&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79455&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79455&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79455&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79455&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79455&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79455&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79455&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79455&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79455&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79455&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79455&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79455&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79455&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79455&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#226464) next »