mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
improve escaping
This commit is contained in:
parent
b02235c275
commit
adf5ec0e6d
3 changed files with 15 additions and 5 deletions
|
|
@ -53,7 +53,8 @@ abstract class Command {
|
||||||
*/
|
*/
|
||||||
public function escapePath($path) {
|
public function escapePath($path) {
|
||||||
$path = str_replace('/', '\\', $path);
|
$path = str_replace('/', '\\', $path);
|
||||||
return '"' . trim(escapeshellarg($path), "'") . '"';
|
$path = str_replace('"', '^"', $path);
|
||||||
|
return '"' . $path . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -61,6 +62,7 @@ abstract class Command {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function escapeLocalPath($path) {
|
public function escapeLocalPath($path) {
|
||||||
return '"' . trim(escapeshellarg($path), "'") . '"';
|
$path = str_replace('"', '\"', $path);
|
||||||
|
return '"' . $path . '"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ class Share {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function read() {
|
public function read() {
|
||||||
fgets($this->pipes[1]);//first line is promt
|
fgets($this->pipes[1]);//first line is prompt
|
||||||
$output = array();
|
$output = array();
|
||||||
$line = fgets($this->pipes[1]);
|
$line = fgets($this->pipes[1]);
|
||||||
while (substr($line, 0, 4) !== 'smb:') { //next prompt functions as delimiter
|
while (substr($line, 0, 4) !== 'smb:') { //next prompt functions as delimiter
|
||||||
|
|
@ -160,6 +160,5 @@ class Share {
|
||||||
$line = fgets($this->pipes[1]);
|
$line = fgets($this->pipes[1]);
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
// return explode(PHP_EOL, stream_get_contents($this->pipes[1]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,8 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEscaping() {
|
public function testEscaping() {
|
||||||
$names = array('simple', 'with spaces');
|
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
|
||||||
|
$names = array('simple', 'with spaces', "single'quote'");
|
||||||
|
|
||||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
||||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||||
|
|
@ -96,6 +97,7 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
||||||
$this->share->get($this->root . '/' . $name . '/foo.txt', $tmpFile2);
|
$this->share->get($this->root . '/' . $name . '/foo.txt', $tmpFile2);
|
||||||
$this->assertEquals($text, file_get_contents($tmpFile2));
|
$this->assertEquals($text, file_get_contents($tmpFile2));
|
||||||
|
unlink($tmpFile2);
|
||||||
|
|
||||||
$this->share->rename($this->root . '/' . $name . '/foo.txt', $this->root . '/' . $name . '/bar.txt');
|
$this->share->rename($this->root . '/' . $name . '/foo.txt', $this->root . '/' . $name . '/bar.txt');
|
||||||
$dir = $this->share->dir($this->root . '/' . $name);
|
$dir = $this->share->dir($this->root . '/' . $name);
|
||||||
|
|
@ -113,9 +115,16 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
||||||
$this->share->get($this->root . '/' . $name, $tmpFile2);
|
$this->share->get($this->root . '/' . $name, $tmpFile2);
|
||||||
$this->assertEquals($text, file_get_contents($tmpFile2));
|
$this->assertEquals($text, file_get_contents($tmpFile2));
|
||||||
|
unlink($tmpFile2);
|
||||||
|
|
||||||
$this->share->del($this->root . '/' . $name);
|
$this->share->del($this->root . '/' . $name);
|
||||||
|
|
||||||
|
$tmpFile2 = tempnam('/tmp', 'smb_test_' . $name);
|
||||||
|
$this->share->put($tmpFile2, $this->root . '/' . $name);
|
||||||
|
$this->assertArrayHasKey($name, $this->share->dir($this->root));
|
||||||
|
$this->share->del($this->root . '/' . $name);
|
||||||
|
unlink($tmpFile2);
|
||||||
|
|
||||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue