|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2017-04-19 04:36 UTC] james at workinout dot com
 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 13:00:01 2025 UTC | 
the quotes I AM seeing are when I do ls -al in a bash shell. see below the filename ON the filesystem has leading and trailing quotes, as I said. i tried escapeshellarg() but it simply puts in backslashes in front of the quotes, which of course, creates a filename that does not exist. drwxr-xr-x 2 james apache 4096 Apr 10 19:21 . drwxr-xr-x 10 james apache 4096 Apr 10 19:21 .. -rw-r--r-- 1 james apache 2900 Apr 10 19:21 '{{ THEME SANITIZED }}.behaviors.js' obviously, the quotes are there...actually, running it all on fedora 25, sorry about that typo strange. downloaded from drupal.org as far as i remember. its weird, I know. cant ever recall seeing a filename with quotes in it. i know about backslashes. used those with fortran in 1975. Entry before: {{ THEME SANITIZED }}.behaviors.js (quotes trimmed by readdir() ) Entry after: \'{{ THEME SANITIZED }}.behaviors.js\' (after using addslashes() ) perhaps echo() and var_dump() use different methods. var_dump using getc/putc ? echo not ?> escapeshellarg() works. after it adds back single quotes around the file there is nothing to add BACK because there was nothing > using echo shows the single quotes are added back no > but as i said below, readdir() is stripping the quotes, DAMNED there are no quotes in the filename, read the responses you got here and try to understand at least the basics > otherwise, I would not need to use escapeshellarg DAMNED you ALWAYS have to use escapeshellarg() when you supply soemting as shell param BECAUSE it filename could contain a space or special chars which are DANGEROUS and could pe interpreted by the caller in unpredicatable ways SIMPLE EXAMPLE: file is called '-rf *' and yes YOU CAN create such file by "touch \*" - guess what happens with passthru("rm /folder/$file");