Properly quote file names in listFiles query for GDrive

This commit is contained in:
Vincent Petry 2015-03-26 12:15:02 +01:00 committed by Lukas Reschke
parent 691c353eed
commit 5c9998179f
2 changed files with 19 additions and 17 deletions

View File

@ -113,7 +113,7 @@ class Google extends \OC\Files\Storage\Common {
if (isset($this->driveFiles[$path])) { if (isset($this->driveFiles[$path])) {
$parentId = $this->driveFiles[$path]->getId(); $parentId = $this->driveFiles[$path]->getId();
} else { } else {
$q = "title='".$name."' and '".$parentId."' in parents and trashed = false"; $q = "title='".rawurlencode($name)."' and '".$parentId."' in parents and trashed = false";
$result = $this->service->files->listFiles(array('q' => $q))->getItems(); $result = $this->service->files->listFiles(array('q' => $q))->getItems();
if (!empty($result)) { if (!empty($result)) {
// Google Drive allows files with the same name, ownCloud doesn't // Google Drive allows files with the same name, ownCloud doesn't

View File

@ -104,13 +104,14 @@ abstract class Storage extends \Test\TestCase {
} }
public function directoryProvider() { public function directoryProvider() {
return array( return [
array('folder'), ['folder'],
array(' folder'), [' folder'],
array('folder '), ['folder '],
array('folder with space'), ['folder with space'],
array('spéciäl földer'), ['spéciäl földer'],
); ['test single\'quote'],
];
} }
function loremFileProvider() { function loremFileProvider() {
@ -163,15 +164,16 @@ abstract class Storage extends \Test\TestCase {
public function copyAndMoveProvider() { public function copyAndMoveProvider() {
return array( return [
array('/source.txt', '/target.txt'), ['/source.txt', '/target.txt'],
array('/source.txt', '/target with space.txt'), ['/source.txt', '/target with space.txt'],
array('/source with space.txt', '/target.txt'), ['/source with space.txt', '/target.txt'],
array('/source with space.txt', '/target with space.txt'), ['/source with space.txt', '/target with space.txt'],
array('/source.txt', '/tärgét.txt'), ['/source.txt', '/tärgét.txt'],
array('/sòurcē.txt', '/target.txt'), ['/sòurcē.txt', '/target.txt'],
array('/sòurcē.txt', '/tärgét.txt'), ['/sòurcē.txt', '/tärgét.txt'],
); ['/single \' quote.txt', '/tar\'get.txt'],
];
} }
public function initSourceAndTarget ($source, $target = null) { public function initSourceAndTarget ($source, $target = null) {