Skip to content

Commit 7b1901b

Browse files
Merge pull request #6 from codenamephp/fix/quoteParameters
Fix: Quote parameters to prevent breaking of command
2 parents 9a737e3 + a0a1d81 commit 7b1901b

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/task/dump/Dump.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function __construct(public iDatabase $database,
4343
public function __invoke() : void {
4444
$dumpfile = $this->dumpfile->getFilename();
4545

46-
$ignoredTableString = implode(' ', array_map(static fn(string $table) => sprintf('--ignore-table %s', $table), $this->database->getTablesToIgnore()));
46+
$ignoredTableString = implode(' ', array_map(static fn(string $table) => sprintf('--ignore-table "%s"', $table), $this->database->getTablesToIgnore()));
4747

4848
$name = $this->database->getName();
4949

50-
$baseCommand = sprintf('mysqldump --user=%s --password=%s --host=%s --port=%d --comments=false --disable-keys --no-autocommit --single-transaction', $this->database->getUser(), $this->database->getPassword(), $this->database->getHost(), $this->database->getPort());
51-
$this->deployerFunctions->run(sprintf('%s --add-drop-table --routines --no-data %s > %s', $baseCommand, $name, $dumpfile));
52-
$this->deployerFunctions->run(sprintf('%s --no-create-info --extended-insert %s %s >> %s', $baseCommand, $ignoredTableString, $name, $dumpfile));
50+
$baseCommand = sprintf('mysqldump --user="%s" --password="%s" --host="%s" --port=%d --comments=false --disable-keys --no-autocommit --single-transaction', $this->database->getUser(), $this->database->getPassword(), $this->database->getHost(), $this->database->getPort());
51+
$this->deployerFunctions->run(sprintf('%s --add-drop-table --routines --no-data "%s" > "%s"', $baseCommand, $name, $dumpfile));
52+
$this->deployerFunctions->run(sprintf('%s --no-create-info --extended-insert %s "%s" >> "%s"', $baseCommand, $ignoredTableString, $name, $dumpfile));
5353
}
5454
}

src/task/import/Import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function __construct(public iDatabase $database,
4343
*/
4444
public function __invoke() : void {
4545
$name = $this->database->getName();
46-
$baseCommand = sprintf('mysql --user=%s --password=%s --host=%s --port=%s', $this->database->getUser(), $this->database->getPassword(), $this->database->getHost(), $this->database->getPort());
46+
$baseCommand = sprintf('mysql --user="%s" --password="%s" --host="%s" --port=%d', $this->database->getUser(), $this->database->getPassword(), $this->database->getHost(), $this->database->getPort());
4747
$this->deployerFunctions->run(sprintf('%s -e "CREATE DATABASE IF NOT EXISTS %s;"', $baseCommand, $name));
48-
$this->deployerFunctions->run(sprintf('%s %s < %s;', $baseCommand, $name, $this->dumpfile->getFilename()));
48+
$this->deployerFunctions->run(sprintf('%s "%s" < "%s";', $baseCommand, $name, $this->dumpfile->getFilename()));
4949
}
5050
}

test/task/dump/DumpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function test__invoke() : void {
4242
$this->sut->dumpfile = $this->createConfiguredMock(iDumpfile::class, ['getFilename' => '/some/folder/file']);
4343

4444
$this->sut->deployerFunctions = \Mockery::mock(iRun::class);
45-
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysqldump --user=myUser --password=topSecret --host=someHost --port=1234 --comments=false --disable-keys --no-autocommit --single-transaction --add-drop-table --routines --no-data myDatabase > /some/folder/file');
46-
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysqldump --user=myUser --password=topSecret --host=someHost --port=1234 --comments=false --disable-keys --no-autocommit --single-transaction --no-create-info --extended-insert --ignore-table ignore1 --ignore-table ignore2 myDatabase >> /some/folder/file');
45+
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysqldump --user="myUser" --password="topSecret" --host="someHost" --port=1234 --comments=false --disable-keys --no-autocommit --single-transaction --add-drop-table --routines --no-data "myDatabase" > "/some/folder/file"');
46+
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysqldump --user="myUser" --password="topSecret" --host="someHost" --port=1234 --comments=false --disable-keys --no-autocommit --single-transaction --no-create-info --extended-insert --ignore-table "ignore1" --ignore-table "ignore2" "myDatabase" >> "/some/folder/file"');
4747

4848
$this->sut->__invoke();
4949
}

test/task/import/ImportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function test__invoke() : void {
3232
$this->sut->dumpfile = $this->createConfiguredMock(iDumpfile::class, ['getFilename' => '/some/folder/file']);
3333

3434
$this->sut->deployerFunctions = Mockery::mock(iRun::class);
35-
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysql --user=myUser --password=topSecret --host=myHost --port=1234 -e "CREATE DATABASE IF NOT EXISTS myDatabase;"');
36-
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysql --user=myUser --password=topSecret --host=myHost --port=1234 myDatabase < /some/folder/file;');
35+
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysql --user="myUser" --password="topSecret" --host="myHost" --port=1234 -e "CREATE DATABASE IF NOT EXISTS myDatabase;"');
36+
$this->sut->deployerFunctions->allows('run')->once()->ordered()->with('mysql --user="myUser" --password="topSecret" --host="myHost" --port=1234 "myDatabase" < "/some/folder/file";');
3737

3838
$this->sut->__invoke();
3939
}

0 commit comments

Comments
 (0)