Bug #74472 [Com]: readdir strips leading and trailing quotes in a filename

From: Date: Wed, 19 Apr 2017 08:27:49 +0000
Subject: Bug #74472 [Com]: readdir strips leading and trailing quotes in a filename
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208662@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74472&edit=1 ID: 74472 Comment by: spam2 at rhsoft dot net Reported by: james at workinout dot com Summary: readdir strips leading and trailing quotes in a filename Status: Not a bug Type: Bug Package: Filesystem function related Operating System: Fedora PHP Version: 7.1.4 Block user comment: N Private report: N New Comment: well, whatever theme he is using - i would stop to use anything from that developer which did not get the basics that a filename on webservers only should have [a-z][0-9]-_ meaning no special chars, no spaces, no uppercase letters anyways the "ls" out put is to help noobs copy&paste stat with spaces versus stat 'with spaces' however, it's not uncommon that outputs of interactive shells are different than what scripts really see (colors, automatic paging and so on) - hence pipe it through "cat" leads to get the non-interactive version because of the pipe Previous Comments: ------------------------------------------------------------------------ [2017-04-19 08:11:05] requinix@php.net Then that would explain why OP thought the filename had quotes. ...wow, that's a stupid decision. ------------------------------------------------------------------------ [2017-04-19 08:03:52] spam2 at rhsoft dot net requinix@php.net: you missed the "actually, running it all on fedora 25" and most likely you use some outdated stuff like Debian here you go: https://bugzilla.redhat.com/show_bug.cgi?id=1361694 https://unix.stackexchange.com/questions/258679/why-is-ls-suddenly-wrapping-items-with-spaces-in-single-quotes [harry@rh:/downloads]$ /bin/ls -la insgesamt 132 drwxrwxrwt 2 root root 122880 19. Apr 10:01 . drwxr-xr-x+ 36 harry root 4096 16. Mär 15:44 .. -rw-r----- 1 harry verwaltung 0 19. Apr 10:01 'with spaces' [harry@rh:/downloads]$ /bin/ls -la | cat insgesamt 132 drwxrwxrwt 2 root root 122880 19. Apr 10:01 . drwxr-xr-x+ 36 harry root 4096 16. Mär 15:44 .. -rw-r----- 1 harry verwaltung 0 19. Apr 10:01 with spaces ------------------------------------------------------------------------ [2017-04-19 06:54:34] requinix@php.net > Nonsense - the quotes you see in ls - la are added by ls itself when the file > name contains spaces and are a quoting so that noobs can copy and paste [citation needed] # touch "'foo'" # touch '"bar"' # touch 'with spaces' # ls -la total 4 drwxrwxrwx 2 root root 0 Apr 18 23:53 . drwx------ 2 root root 0 Apr 18 23:49 .. -rw-rw-rw- 1 root root 0 Apr 18 23:53 "bar" -rw-rw-rw- 1 root root 0 Apr 18 23:53 'foo' -rw-rw-rw- 1 root root 0 Apr 18 23:53 with spaces # ls -la | cat total 4 drwxrwxrwx 2 root root 0 Apr 18 23:53 . drwx------ 2 root root 0 Apr 18 23:49 .. -rw-rw-rw- 1 root root 0 Apr 18 23:53 "bar" -rw-rw-rw- 1 root root 0 Apr 18 23:53 'foo' -rw-rw-rw- 1 root root 0 Apr 18 23:53 with spaces # ls -laQ total 4 drwxrwxrwx 2 root root 0 Apr 18 23:53 "." drwx------ 2 root root 0 Apr 18 23:49 ".." -rw-rw-rw- 1 root root 0 Apr 18 23:53 "\"bar\"" -rw-rw-rw- 1 root root 0 Apr 18 23:53 "'foo'" -rw-rw-rw- 1 root root 0 Apr 18 23:53 "with spaces" ------------------------------------------------------------------------ [2017-04-19 06:47:12] spam2 at rhsoft dot net Nonsense - the quotes you see in ls - la are added by ls itself when the file name contains spaces and are a quoting so that noobs can copy and paste Just type "ls - la | cat" and you see what a non-interactive shell sees RTFM escapeshellargs ------------------------------------------------------------------------ [2017-04-19 06:27:21] requinix@php.net echo will output a thing as it is with no modifications, besides converting it to a string if it isn't one already. var_dump, being a debugging tool, will output using a representation that makes it easier to know what the thing's exact type and value is; strings will have quotes around them to signify that they are strings, for instance. As you can see, readdir is not stripping quotes because there are no quotes to begin with. You have code that is adding the quotes somewhere, then on top of it apparently using addslashes which will escape the quotes with backslashes. I don't know why the code is doing any of that but I'm confident it should not be. Like I said, you need to be using escapeshellarg to put strings into shell commands. It does all the work for you - don't put quotes around the string yourself, don't addslashes yourself. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=74472 -- Edit this bug report at https://bugs.php.net/bug.php?id=74472&edit=1

« previous php.bugs (#208662) next »