Commit 36823b2c authored by Thomas Müller's avatar Thomas Müller Committed by Thomas Müller
Browse files

Allow files containing 4-byte chars in case the database supports it

parent 6f9f592c
......@@ -246,4 +246,11 @@ class Db implements IDb {
public function getTransactionIsolation() {
return $this->connection->getTransactionIsolation();
}
/**
* @inheritdoc
*/
public function allows4ByteCharacters() {
return $this->connection->allows4ByteCharacters();
}
}
......@@ -33,6 +33,7 @@ use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Exception\ConstraintViolationException;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Schema;
use OC\DB\QueryBuilder\QueryBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
......@@ -427,4 +428,19 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
$migrator->migrate($toSchema);
}
/**
* Are 4-byte characters allowed or only 3-byte
*
* @return bool
* @since 10.0
*/
public function allows4ByteCharacters() {
if (!$this->getDatabasePlatform() instanceof MySqlPlatform) {
return true;
}
if ($this->getParams()['charset'] === 'utf8mb4') {
return true;
}
return false;
}
}
......@@ -1793,13 +1793,15 @@ class View {
throw new InvalidPathException($l10n->t('Dot files are not allowed'));
}
// verify database - e.g. mysql only 3-byte chars
if (preg_match('%(?:
if (!\OC::$server->getDatabaseConnection()->allows4ByteCharacters()) {
// verify database - e.g. mysql only 3-byte chars
if (preg_match('%(?:
\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)%xs', $fileName)) {
throw new InvalidPathException($l10n->t('4-byte characters are not supported in file names'));
throw new InvalidPathException($l10n->t('4-byte characters are not supported in file names'));
}
}
try {
......
......@@ -276,4 +276,11 @@ interface IDBConnection {
*/
public function getTransactionIsolation();
/**
* Are 4-byte characters allowed or only 3-byte
*
* @return bool
* @since 10.0
*/
public function allows4ByteCharacters();
}
......@@ -400,7 +400,13 @@ class LegacyDBTest extends \Test\TestCase {
/**
* @dataProvider insertAndSelectDataProvider
*/
public function testInsertAndSelectData($expected, $skipOnMysql) {
public function testInsertAndSelectData($expected, $requires4ByteSupport) {
$connection = \OC::$server->getDatabaseConnection();
if($requires4ByteSupport && !$connection->allows4ByteCharacters()) {
$this->markTestSkipped('Test requires 4-byte support which is not present');
}
$table = "*PREFIX*{$this->text_table}";
$query = OC_DB::prepare("INSERT INTO `$table` (`textfield`) VALUES (?)");
......@@ -408,10 +414,6 @@ class LegacyDBTest extends \Test\TestCase {
$this->assertEquals(1, $result);
$actual = OC_DB::prepare("SELECT `textfield` FROM `$table`")->execute()->fetchOne();
$config = \OC::$server->getConfig();
if($skipOnMysql && $config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false) === false) {
return;
}
$this->assertSame($expected, $actual);
}
......
......@@ -9,6 +9,7 @@ namespace Test\Files;
use OC\Files\Storage\Local;
use OC\Files\View;
use OCP\Files\InvalidPathException;
/**
* Class PathVerificationTest
......@@ -79,10 +80,12 @@ class PathVerificationTest extends \Test\TestCase {
/**
* @dataProvider providesAstralPlane
* @expectedException \OCP\Files\InvalidPathException
* @expectedExceptionMessage 4-byte characters are not supported in file names
*/
public function testPathVerificationAstralPlane($fileName) {
if (!\OC::$server->getDatabaseConnection()->allows4ByteCharacters()) {
$this->expectException(InvalidPathException::class);
$this->expectExceptionMessage('4-byte characters are not supported in file names');
}
$this->view->verifyPath('', $fileName);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment