1
0
Fork 0

Fix escaping of URLs in Perforce and Subversion drivers

pull/7589/head
Jordi Boggiano 2018-08-25 17:45:08 +02:00
parent 3d01ef28fa
commit bf125295df
10 changed files with 32 additions and 31 deletions

View File

@ -226,7 +226,7 @@ class FossilDriver extends VcsDriver
return false; return false;
} }
$process = new ProcessExecutor(); $process = new ProcessExecutor($io);
// check whether there is a fossil repo in that path // check whether there is a fossil repo in that path
if ($process->execute('fossil info', $output, $url) === 0) { if ($process->execute('fossil info', $output, $url) === 0) {
return true; return true;

View File

@ -211,7 +211,7 @@ class HgDriver extends VcsDriver
return false; return false;
} }
$process = new ProcessExecutor(); $process = new ProcessExecutor($io);
// check whether there is a hg repo in that path // check whether there is a hg repo in that path
if ($process->execute('hg summary', $output, $url) === 0) { if ($process->execute('hg summary', $output, $url) === 0) {
return true; return true;
@ -222,7 +222,7 @@ class HgDriver extends VcsDriver
return false; return false;
} }
$processExecutor = new ProcessExecutor(); $processExecutor = new ProcessExecutor($io);
$exit = $processExecutor->execute(sprintf('hg identify %s', ProcessExecutor::escape($url)), $ignored); $exit = $processExecutor->execute(sprintf('hg identify %s', ProcessExecutor::escape($url)), $ignored);
return $exit === 0; return $exit === 0;

View File

@ -307,10 +307,10 @@ class SvnDriver extends VcsDriver
return false; return false;
} }
$processExecutor = new ProcessExecutor(); $processExecutor = new ProcessExecutor($io);
$exit = $processExecutor->execute( $exit = $processExecutor->execute(
"svn info --non-interactive {$url}", "svn info --non-interactive ".ProcessExecutor::escape('{'.$url.'}'),
$ignoredOutput $ignoredOutput
); );

View File

@ -44,7 +44,7 @@ class Bitbucket
{ {
$this->io = $io; $this->io = $io;
$this->config = $config; $this->config = $config;
$this->process = $process ?: new ProcessExecutor; $this->process = $process ?: new ProcessExecutor($io);
$this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config); $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config);
$this->time = $time; $this->time = $time;
} }

View File

@ -527,7 +527,7 @@ class Filesystem
protected function getProcess() protected function getProcess()
{ {
return new ProcessExecutor; return $this->processExecutor;
} }
/** /**

View File

@ -39,7 +39,7 @@ class GitHub
{ {
$this->io = $io; $this->io = $io;
$this->config = $config; $this->config = $config;
$this->process = $process ?: new ProcessExecutor; $this->process = $process ?: new ProcessExecutor($io);
$this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config); $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config);
} }

View File

@ -40,7 +40,7 @@ class GitLab
{ {
$this->io = $io; $this->io = $io;
$this->config = $config; $this->config = $config;
$this->process = $process ?: new ProcessExecutor(); $this->process = $process ?: new ProcessExecutor($io);
$this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config); $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config);
} }

View File

@ -58,7 +58,7 @@ class Perforce
{ {
$output = null; $output = null;
return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output); return 0 === $processExecutor->execute('p4 -p ' . ProcessExecutor::escape($url) . ' info -s', $output);
} }
public function initialize($repoConfig) public function initialize($repoConfig)
@ -105,7 +105,7 @@ class Perforce
public function cleanupClientSpec() public function cleanupClientSpec()
{ {
$client = $this->getClient(); $client = $this->getClient();
$task = 'client -d ' . $client; $task = 'client -d ' . ProcessExecutor::escape($client);
$useP4Client = false; $useP4Client = false;
$command = $this->generateP4Command($task, $useP4Client); $command = $this->generateP4Command($task, $useP4Client);
$this->executeCommand($command); $this->executeCommand($command);
@ -383,7 +383,7 @@ class Perforce
if ($this->windowsFlag) { if ($this->windowsFlag) {
$this->windowsLogin($password); $this->windowsLogin($password);
} else { } else {
$command = 'echo ' . $password . ' | ' . $this->generateP4Command(' login -a', false); $command = 'echo ' . ProcessExecutor::escape($password) . ' | ' . $this->generateP4Command(' login -a', false);
$exitCode = $this->executeCommand($command); $exitCode = $this->executeCommand($command);
$result = trim($this->commandResult); $result = trim($this->commandResult);
if ($exitCode) { if ($exitCode) {
@ -408,7 +408,7 @@ class Perforce
{ {
$path = $this->getFilePath($file, $identifier); $path = $this->getFilePath($file, $identifier);
$command = $this->generateP4Command(' print ' . $path); $command = $this->generateP4Command(' print ' . ProcessExecutor::escape($path));
$this->executeCommand($command); $this->executeCommand($command);
$result = $this->commandResult; $result = $this->commandResult;
@ -429,7 +429,7 @@ class Perforce
} }
$path = substr($identifier, 0, $index) . '/' . $file . substr($identifier, $index); $path = substr($identifier, 0, $index) . '/' . $file . substr($identifier, $index);
$command = $this->generateP4Command(' files ' . $path, false); $command = $this->generateP4Command(' files ' . ProcessExecutor::escape($path), false);
$this->executeCommand($command); $this->executeCommand($command);
$result = $this->commandResult; $result = $this->commandResult;
$index2 = strpos($result, 'no such file(s).'); $index2 = strpos($result, 'no such file(s).');
@ -452,7 +452,7 @@ class Perforce
if (!$this->isStream()) { if (!$this->isStream()) {
$possibleBranches[$this->p4Branch] = $this->getStream(); $possibleBranches[$this->p4Branch] = $this->getStream();
} else { } else {
$command = $this->generateP4Command('streams //' . $this->p4Depot . '/...'); $command = $this->generateP4Command('streams '.ProcessExecutor::escape('//' . $this->p4Depot . '/...'));
$this->executeCommand($command); $this->executeCommand($command);
$result = $this->commandResult; $result = $this->commandResult;
$resArray = explode(PHP_EOL, $result); $resArray = explode(PHP_EOL, $result);
@ -464,7 +464,7 @@ class Perforce
} }
} }
} }
$command = $this->generateP4Command('changes '. $this->getStream() . '/...', false); $command = $this->generateP4Command('changes '. ProcessExecutor::escape($this->getStream() . '/...'), false);
$this->executeCommand($command); $this->executeCommand($command);
$result = $this->commandResult; $result = $this->commandResult;
$resArray = explode(PHP_EOL, $result); $resArray = explode(PHP_EOL, $result);
@ -527,7 +527,7 @@ class Perforce
return null; return null;
} }
$label = substr($reference, $index); $label = substr($reference, $index);
$command = $this->generateP4Command(' changes -m1 ' . $label); $command = $this->generateP4Command(' changes -m1 ' . ProcessExecutor::escape($label));
$this->executeCommand($command); $this->executeCommand($command);
$changes = $this->commandResult; $changes = $this->commandResult;
if (strpos($changes, 'Change') !== 0) { if (strpos($changes, 'Change') !== 0) {
@ -555,7 +555,7 @@ class Perforce
} }
$index = strpos($fromReference, '@'); $index = strpos($fromReference, '@');
$main = substr($fromReference, 0, $index) . '/...'; $main = substr($fromReference, 0, $index) . '/...';
$command = $this->generateP4Command('filelog ' . $main . '@' . $fromChangeList. ',' . $toChangeList); $command = $this->generateP4Command('filelog ' . ProcessExecutor::escape($main . '@' . $fromChangeList. ',' . $toChangeList));
$this->executeCommand($command); $this->executeCommand($command);
return $this->commandResult; return $this->commandResult;

View File

@ -79,7 +79,7 @@ class Svn
$this->url = $url; $this->url = $url;
$this->io = $io; $this->io = $io;
$this->config = $config; $this->config = $config;
$this->process = $process ?: new ProcessExecutor; $this->process = $process ?: new ProcessExecutor($io);
} }
public static function cleanEnv() public static function cleanEnv()

View File

@ -14,6 +14,7 @@ namespace Composer\Test\Util;
use Composer\Util\Perforce; use Composer\Util\Perforce;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Composer\Util\ProcessExecutor;
/** /**
* @author Matt Whittom <Matt.Whittom@veteransunited.com> * @author Matt Whittom <Matt.Whittom@veteransunited.com>
@ -344,7 +345,7 @@ class PerforceTest extends TestCase
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port streams //depot/...'; $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port streams '.ProcessExecutor::escape('//depot/...');
$this->processExecutor->expects($this->at(0)) $this->processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -357,7 +358,7 @@ class PerforceTest extends TestCase
} }
) )
); );
$expectedCommand2 = 'p4 -u user -p port changes //depot/branch/...'; $expectedCommand2 = 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/branch/...');
$expectedCallback = function ($command, &$output) { $expectedCallback = function ($command, &$output) {
$output = 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; $output = 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\'';
@ -374,7 +375,7 @@ class PerforceTest extends TestCase
public function testGetBranchesWithoutStream() public function testGetBranchesWithoutStream()
{ {
$expectedCommand = 'p4 -u user -p port changes //depot/...'; $expectedCommand = 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/...');
$expectedCallback = function ($command, &$output) { $expectedCallback = function ($command, &$output) {
$output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; $output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\'';
@ -458,7 +459,7 @@ class PerforceTest extends TestCase
public function testGetComposerInformationWithoutLabelWithoutStream() public function testGetComposerInformationWithoutLabelWithoutStream()
{ {
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/composer.json'; $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json');
$this->processExecutor->expects($this->at(0)) $this->processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -484,7 +485,7 @@ class PerforceTest extends TestCase
public function testGetComposerInformationWithLabelWithoutStream() public function testGetComposerInformationWithLabelWithoutStream()
{ {
$expectedCommand = 'p4 -u user -p port files //depot/composer.json@0.0.1'; $expectedCommand = 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/composer.json@0.0.1');
$this->processExecutor->expects($this->at(0)) $this->processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -498,7 +499,7 @@ class PerforceTest extends TestCase
) )
); );
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/composer.json@10001'; $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json@10001');
$this->processExecutor->expects($this->at(1)) $this->processExecutor->expects($this->at(1))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -527,7 +528,7 @@ class PerforceTest extends TestCase
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/composer.json'; $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json');
$this->processExecutor->expects($this->at(0)) $this->processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -555,7 +556,7 @@ class PerforceTest extends TestCase
public function testGetComposerInformationWithLabelWithStream() public function testGetComposerInformationWithLabelWithStream()
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectedCommand = 'p4 -u user -p port files //depot/branch/composer.json@0.0.1'; $expectedCommand = 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/branch/composer.json@0.0.1');
$this->processExecutor->expects($this->at(0)) $this->processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -569,7 +570,7 @@ class PerforceTest extends TestCase
) )
); );
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/composer.json@10001'; $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json@10001');
$this->processExecutor->expects($this->at(1)) $this->processExecutor->expects($this->at(1))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand)) ->with($this->equalTo($expectedCommand))
@ -621,7 +622,7 @@ class PerforceTest extends TestCase
{ {
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$expectedCommand = 'p4 -p perforce.does.exist:port info -s'; $expectedCommand = 'p4 -p '.ProcessExecutor::escape('perforce.does.exist:port').' info -s';
$processExecutor->expects($this->at(0)) $processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null)) ->with($this->equalTo($expectedCommand), $this->equalTo(null))
@ -642,7 +643,7 @@ class PerforceTest extends TestCase
{ {
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$expectedCommand = 'p4 -p perforce.does.exist:port info -s'; $expectedCommand = 'p4 -p '.ProcessExecutor::escape('perforce.does.exist:port').' info -s';
$processExecutor->expects($this->at(0)) $processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null)) ->with($this->equalTo($expectedCommand), $this->equalTo(null))
@ -712,7 +713,7 @@ class PerforceTest extends TestCase
$this->perforce->setFilesystem($fs); $this->perforce->setFilesystem($fs);
$testClient = $this->perforce->getClient(); $testClient = $this->perforce->getClient();
$expectedCommand = 'p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . $testClient; $expectedCommand = 'p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . ProcessExecutor::escape($testClient);
$this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); $this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand));
$fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec());