Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request from GHSA-frqg-7g38-6gcf
  • Loading branch information
Seldaek committed Oct 5, 2021
1 parent 532c6e7 commit b3eebeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Composer/Command/HomeCommand.php
Expand Up @@ -129,7 +129,7 @@ private function openBrowser($url)

$process = new ProcessExecutor($this->getIO());
if (Platform::isWindows()) {
return $process->execute('start "web" explorer "' . $url . '"', $output);
return $process->execute('start "web" explorer ' . $url, $output);
}

$linux = $process->execute('which xdg-open', $output);
Expand Down
47 changes: 14 additions & 33 deletions src/Composer/Util/ProcessExecutor.php
Expand Up @@ -455,48 +455,29 @@ public static function escape($argument)
}

/**
* Copy of ProcessUtils::escapeArgument() that is deprecated in Symfony 3.3 and removed in Symfony 4.
* Copy of Symfony's Process::escapeArgument() which is private
*
* @param string $argument
*
* @return string
*/
private static function escapeArgument($argument)
{
//Fix for PHP bug #43784 escapeshellarg removes % from given string
//Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
//@see https://bugs.php.net/bug.php?id=43784
//@see https://bugs.php.net/bug.php?id=49446
if ('\\' === DIRECTORY_SEPARATOR) {
if ((string) $argument === '') {
return escapeshellarg($argument);
}

$escapedArgument = '';
$quote = false;
foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
// Avoid environment variable expansion
$escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
} else {
// escape trailing backslash
if ('\\' === substr($part, -1)) {
$part .= '\\';
}
$quote = true;
$escapedArgument .= $part;
}
}
if ($quote) {
$escapedArgument = '"'.$escapedArgument.'"';
}

return $escapedArgument;
if ('' === $argument || null === $argument) {
return '""';
}
if ('\\' !== \DIRECTORY_SEPARATOR) {
return "'".str_replace("'", "'\\''", $argument)."'";
}
if (str_contains($argument, "\0")) {
$argument = str_replace("\0", '?', $argument);
}
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
return $argument;
}
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);

return "'".str_replace("'", "'\\''", $argument)."'";
return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"';
}

/**
Expand Down

0 comments on commit b3eebeb

Please sign in to comment.