Bug #74472 [Nab]: readdir strips leading and trailing quotes in a filename
| From: | requinix@php.net | Date: | Wed, 19 Apr 2017 08:11:10 +0000 |
| Subject: | Bug #74472 [Nab]: readdir strips leading and trailing quotes in a filename | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208661@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
Updated by: requinix@php.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: osx 10.12
+Operating System: Fedora
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
Then that would explain why OP thought the filename had quotes.
...wow, that's a stupid decision.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2017-04-19 06:18:21] james at workinout dot com
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 ?
------------------------------------------------------------------------
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