Req #74472 [NEW]: readdir strips leading and trailing quotes in a filename

From: Date: Wed, 19 Apr 2017 04:36:40 +0000
Subject: Req #74472 [NEW]: readdir strips leading and trailing quotes in a filename
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208651@lists.php.net to get a copy of this message
From: james at workinout dot com Operating system: osx 10.12 PHP version: 7.1.4 Package: Filesystem function related Bug Type: Feature/Change Request Bug description:readdir strips leading and trailing quotes in a filename Description: ------------ in drupal, some files named with leading and trailing quotes filename === '{{ THEME SANITIZED }}.behaviors.js' $entry = readdir() --- > $entry === -> {{ THEME SANITIZED }}.behaviors.js (NO QUOTES) stat will not work because the stripped quotes are needed: stat complains like below: stat --format=%G (command used..) stat: cannot stat '{{': No such file or directory stat: cannot stat 'THEME': No such file or directory stat: cannot stat 'SANITIZED': No such file or directory stat: cannot stat '}}.behaviors.js': No such file or directory stat: cannot stat '{{': No such file or directory stat: cannot stat 'THEME': No such file or directory stat: cannot stat 'SANITIZED': No such file or directory stat: cannot stat '}}.behaviors.js': No such file or directory Test script: --------------- Solution is to put the quotes back in filename. $entry = "'" . $entry . "'". stat works ok then... if ($handle = opendir($name)) { while (false !== ($entry = readdir($handle))) { if (preg_match('/\.$|\..$/', $entry)) { continue; } //special case for filenames with single quotes (they are stripped by readdir() ) // used in omega themes with {{ in the filename.. if(preg_match('/\{/', $entry)) { $entry = "'" . $entry . "'"; } <after this, stat will work.... Expected result: ---------------- providing an optional argument in readdir() to not strip leading,trailing quotes would be useful -- Edit bug report at https://bugs.php.net/bug.php?id=74472&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74472&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74472&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74472&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74472&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74472&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74472&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74472&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74472&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74472&r=support Expected behavior: https://bugs.php.net/fix.php?id=74472&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74472&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74472&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74472&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74472&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74472&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74472&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74472&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74472&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74472&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74472&r=mysqlcfg

« previous php.bugs (#208651) next »