no translation service in common storage class

This commit is contained in:
Thomas Müller 2015-03-04 14:03:47 +01:00
parent 2367797c17
commit 3623f14e73
5 changed files with 94 additions and 19 deletions

View File

@ -13,7 +13,9 @@ use OC\Files\Cache\Scanner;
use OC\Files\Cache\Storage;
use OC\Files\Filesystem;
use OC\Files\Cache\Watcher;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException;
/**
* Storage backend class for providing common filesystem operation methods
@ -476,7 +478,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
$this->scanForInvalidCharacters($fileName, "\\/<>:\"|?*");
$reservedNames = ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9'];
if (in_array(strtoupper($fileName), $reservedNames)) {
throw new InvalidPathException($this->t("File name is a reserved word"));
throw new ReservedWordException();
}
}
@ -489,7 +491,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
$this->scanForInvalidCharacters($fileName, "\\/");
$reservedNames = ['*'];
if (in_array($fileName, $reservedNames)) {
throw new InvalidPathException($this->t('File name is a reserved word'));
throw new ReservedWordException();
}
}
@ -501,19 +503,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
private function scanForInvalidCharacters($fileName, $invalidChars) {
foreach(str_split($invalidChars) as $char) {
if (strpos($fileName, $char) !== false) {
throw new InvalidPathException($this->t('File name contains at least one invalid characters'));
throw new InvalidCharacterInPathException();
}
}
$sanitizedFileName = filter_var($fileName, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
if($sanitizedFileName !== $fileName) {
throw new InvalidPathException($this->t('File name contains at least one invalid characters'));
throw new InvalidCharacterInPathException();
}
}
private function t($string) {
$l10n = \OC::$server->getL10N('lib');
return $l10n->t($string);
}
}

View File

@ -11,7 +11,9 @@ namespace OC\Files;
use OC\Files\Cache\Updater;
use OC\Files\Mount\MoveableMount;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException;
/**
* Class to provide access to ownCloud filesystem via a "view", and methods for
@ -1563,8 +1565,14 @@ class View {
throw new InvalidPathException($l10n->t('4-byte characters are not supported in file names'));
}
/** @type \OCP\Files\Storage $storage */
list($storage, $internalPath) = $this->resolvePath($path);
$storage->verifyPath($internalPath, $fileName);
try {
/** @type \OCP\Files\Storage $storage */
list($storage, $internalPath) = $this->resolvePath($path);
$storage->verifyPath($internalPath, $fileName);
} catch (ReservedWordException $ex) {
throw new InvalidPathException($l10n->t('File name is a reserved word'));
} catch (InvalidCharacterInPathException $ex) {
throw new InvalidPathException($l10n->t('File name contains at least one invalid characters'));
}
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* ownCloud
*
* @author Thomas Müller
* @copyright 2013 Thomas Müller deepdiver@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Public interface of ownCloud for apps to use.
* Files/InvalidCharacterInPathException class
*/
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP\Files;
/**
* Exception for invalid path
*/
class InvalidCharacterInPathException extends InvalidPathException {
}

View File

@ -0,0 +1,37 @@
<?php
/**
* ownCloud
*
* @author Thomas Müller
* @copyright 2013 Thomas Müller deepdiver@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Public interface of ownCloud for apps to use.
* Files/ReservedWordException class
*/
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP\Files;
/**
* Exception for invalid path
*/
class ReservedWordException extends InvalidPathException {
}

View File

@ -78,8 +78,7 @@ class PathVerification extends \Test\TestCase {
/**
* @dataProvider providesInvalidCharsWindows
* @expectedException \OCP\Files\InvalidPathException
* @expectedExceptionMessage File name contains at least one invalid characters
* @expectedException \OCP\Files\InvalidCharacterInPathException
*/
public function testPathVerificationInvalidCharsWindows($fileName) {
$storage = new Local(['datadir' => '']);
@ -136,8 +135,7 @@ class PathVerification extends \Test\TestCase {
/**
* @dataProvider providesInvalidCharsPosix
* @expectedException \OCP\Files\InvalidPathException
* @expectedExceptionMessage File name contains at least one invalid characters
* @expectedException \OCP\Files\InvalidCharacterInPathException
*/
public function testPathVerificationInvalidCharsPosix($fileName) {
$storage = new Local(['datadir' => '']);
@ -187,8 +185,7 @@ class PathVerification extends \Test\TestCase {
/**
* @dataProvider providesReservedNamesWindows
* @expectedException \OCP\Files\InvalidPathException
* @expectedExceptionMessage File name is a reserved word
* @expectedException \OCP\Files\ReservedWordException
*/
public function testPathVerificationReservedNamesWindows($fileName) {
$storage = new Local(['datadir' => '']);