[Process] Non ASCII characters disappearing during the escapeshellarg #21485

Closed
wants to merge 8 commits into
from

Projects

None yet

3 participants

@GuillaumeVerdon
Contributor
GuillaumeVerdon commented Feb 1, 2017 edited

If the LC_CTYPE is not set at UTF-8, the escapeshellarg() function will remove every non-ascii characters.

As it's usual in europe to have directories with non-ascii chars in their name (ex : ~/Vidéos) the function should throw an exception if we're trying to submit it an argument containing non-ascii param and the LC_CTYPE is not set to use UTF-8

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass?
Fixed tickets
License MIT
Doc PR

I had this issue while using the lib ffmpeg and giving it a path like "~/Vidéos" the "é" chars was disappearing from the command giving a RuntimeException.

The problem was my LC_CTYPE that wasn't set properly, I believe an exception should be raised before the RuntimeException to warn the user of that behavior

@GuillaumeVerdon GuillaumeVerdon Avoid to escape non-ascii characters in argument
If the LC_CTYPE is not set at UTF-8, the escapeshellarg() function will remove every non-ascii characters.

As it's usual in europe to have directories with non-ascii chars in their name (ex : ~/Vidéos) the function should throw an exception if we're trying to submit it an argument containing non-ascii param and the LC_CTYPE is not set to use UTF-8
78620a5
@stof stof changed the base branch to symfony:3.2 from symfony:2.3 Feb 1, 2017
@GuillaumeVerdon GuillaumeVerdon changed the title from Escapeargumentfix to [Process] Non ASCII characters disappearing during the escapeshellarg Feb 1, 2017
@nicolas-grekas
Member
nicolas-grekas commented Feb 1, 2017 edited

what about doing escaping ourselves instead?
return "'".str_replace(array('\\', "'"), array('\\\\', "\\'"), $argument)."'";
can you try it? does it work?
if yes, can you pelase update your PR and add a test case?

GuillaumeVerdon added some commits Feb 1, 2017
@GuillaumeVerdon GuillaumeVerdon Replacing the primitive escapeshellarg() on linux systems 597e1a8
@GuillaumeVerdon GuillaumeVerdon Added test case for non-ascii chars
7839ba0
@GuillaumeVerdon GuillaumeVerdon Corrected code style
a21daa1
@GuillaumeVerdon GuillaumeVerdon Corrected code style 7734023
@GuillaumeVerdon GuillaumeVerdon Merge branch 'escapeargumentfix' of https://github.com/GuillaumeVerdo…
…n/symfony into escapeargumentfix
95e9c72
@GuillaumeVerdon GuillaumeVerdon Amended last commit.. I'm tired
b255302
@GuillaumeVerdon GuillaumeVerdon Removing ghost tabulation
93201c1
@GuillaumeVerdon
Contributor
GuillaumeVerdon commented Feb 1, 2017 edited

I edited the current test case and the logic for Linux, as I don't know how the function is working on windows I didn't patch it.

ProcessUtilsTest.php is passing on my environment

@nicolas-grekas
Member

👍 (to be merged on 2.7, Windows is unaffected)

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Feb 1, 2017
@nicolas-grekas
Member

Thank you @GuillaumeVerdon.

@nicolas-grekas nicolas-grekas added a commit that referenced this pull request Feb 2, 2017
@nicolas-grekas nicolas-grekas bug #21485 [Process] Non ASCII characters disappearing during the esc…
…apeshellarg (GuillaumeVerdon)

This PR was submitted for the 3.2 branch but it was merged into the 2.7 branch instead (closes #21485).

Discussion
----------

[Process] Non ASCII characters disappearing during the escapeshellarg

If the LC_CTYPE is not set at UTF-8, the escapeshellarg() function will remove every non-ascii characters.

As it's usual in europe to have directories with non-ascii chars in their name (ex : ~/Vidéos) the function should throw an exception if we're trying to submit it an argument containing non-ascii param and the LC_CTYPE is not set to use UTF-8

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   |
| Fixed tickets |
| License       | MIT
| Doc PR        |

I had this issue while using the lib ffmpeg and giving it a path like "~/Vidéos" the "é" chars was disappearing from the command giving a RuntimeException.

The problem was my LC_CTYPE that wasn't set properly, I believe an exception should be raised before the RuntimeException to warn the user of that behavior

Commits
-------

3779f3f [Process] Non ASCII characters disappearing during the escapeshellarg
01a0250
@GuillaumeVerdon GuillaumeVerdon deleted the unknown repository branch Feb 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment