Skip to content

Commit e074880

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
2 parents 4246b6d + 0f30f21 commit e074880

10 files changed

Lines changed: 238 additions & 161 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16461,7 +16461,7 @@ parameters:
1646116461
Use dependency injection instead\.$#
1646216462
'''
1646316463
identifier: staticMethod.deprecated
16464-
count: 11
16464+
count: 12
1646516465
path: tests/unit/Server/PrivilegesTest.php
1646616466

1646716467
-

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10345,6 +10345,7 @@
1034510345
<code><![CDATA[Config::getInstance()]]></code>
1034610346
<code><![CDATA[Config::getInstance()]]></code>
1034710347
<code><![CDATA[Config::getInstance()]]></code>
10348+
<code><![CDATA[Config::getInstance()]]></code>
1034810349
</DeprecatedMethod>
1034910350
</file>
1035010351
<file src="tests/unit/Server/SelectTest.php">

src/Query/Compatibility.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ public static function isVectorSupported(DatabaseInterface $dbi): bool
190190
$dbi->isMySql() && $dbi->getVersion() >= 90000; // 9.0.0
191191
}
192192

193+
/**
194+
* Check whether the database supports XMLTYPE data type
195+
*
196+
* @return bool true if XMLTYPE is supported
197+
*/
198+
public static function isXmlTypeSupported(DatabaseInterface $dbi): bool
199+
{
200+
// @see: https://mariadb.com/docs/server/reference/data-types/string-data-types/xmltype
201+
return $dbi->isMariaDB() && $dbi->getVersion() >= 120300; // 12.3.0
202+
}
203+
193204
/**
194205
* Returns whether the database server supports virtual columns
195206
*/

src/Sanitize.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,8 @@ public static function convertBBCode(string $message, bool $safe = false): strin
226226
*/
227227
public static function sanitizeFilename(string $filename, bool $replaceDots = false): string
228228
{
229-
$pattern = '/[^A-Za-z0-9_';
230-
// if we don't have to replace dots
231-
if (! $replaceDots) {
232-
// then add the dot to the list of legit characters
233-
$pattern .= '.';
234-
}
235-
236-
$pattern .= '-]/';
229+
// Keep only numbers (N), letters (L), dash, underbar, and maybe dot
230+
$pattern = '/[^\p{N}\p{L}' . ($replaceDots ? '' : '.') . '_-]/u';
237231

238232
return preg_replace($pattern, '_', $filename);
239233
}

src/Types.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public function getTypeDescription(string $type): string
292292
'UUID' => __('128-bit UUID (Universally Unique Identifier)'),
293293
'VECTOR' => __('Stores vector data optimized for operations '
294294
. 'such as similarity search and machine learning applications'),
295+
'XMLTYPE' => __('Intended for storage of XML data'),
295296
default => '',
296297
};
297298
}
@@ -592,6 +593,7 @@ public function getColumns(): array
592593
$isJsonSupported = Compatibility::isJsonSupported($this->dbi);
593594
$isUUIDSupported = Compatibility::isUUIDSupported($this->dbi);
594595
$isVectorSupported = Compatibility::isVectorSupported($this->dbi);
596+
$isXmlTypeSupported = Compatibility::isXmlTypeSupported($this->dbi);
595597

596598
// most used types
597599
$ret = ['INT', 'VARCHAR', 'TEXT', 'DATE'];
@@ -672,6 +674,10 @@ public function getColumns(): array
672674
$ret['VECTOR'] = ['VECTOR'];
673675
}
674676

677+
if ($isXmlTypeSupported) {
678+
$ret['XML'] = ['XMLTYPE'];
679+
}
680+
675681
return $ret;
676682
}
677683

tests/unit/Query/CompatibilityTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,27 @@ public function testIsVectorSupported(bool $expected, bool $isMariaDb, int $vers
6868
self::assertSame($expected, Compatibility::isVectorSupported($dbiStub));
6969
}
7070

71-
/**
72-
* @return mixed[][]
73-
* @psalm-return array<string, array{bool, bool, int}>
74-
*/
71+
/** @return array<string, array{bool, bool, int}> */
72+
public static function providerForTestIsXmlTypeSupported(): array
73+
{
74+
return [
75+
'MariaDB 12.2.99' => [false, true, 120299],
76+
'MariaDB 12.3.0' => [true, true, 120300],
77+
];
78+
}
79+
80+
#[DataProvider('providerForTestIsXmlTypeSupported')]
81+
public function testIsXmlTypeSupported(bool $expected, bool $isMariaDb, int $version): void
82+
{
83+
$dbiStub = self::createStub(DatabaseInterface::class);
84+
85+
$dbiStub->method('isMariaDB')->willReturn($isMariaDb);
86+
$dbiStub->method('getVersion')->willReturn($version);
87+
88+
self::assertSame($expected, Compatibility::isXmlTypeSupported($dbiStub));
89+
}
90+
91+
/** @return array<string, array{bool, bool, int}> */
7592
public static function providerForTestIsUUIDSupported(): array
7693
{
7794
return [

tests/unit/SanitizeTest.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
use PHPUnit\Framework\Attributes\CoversClass;
1010
use PHPUnit\Framework\Attributes\DataProvider;
1111

12+
use function implode;
13+
use function range;
14+
use function str_repeat;
15+
1216
#[CoversClass(Sanitize::class)]
1317
class SanitizeTest extends AbstractTestCase
1418
{
@@ -139,15 +143,28 @@ public function testBBCode(): void
139143
);
140144
}
141145

142-
/**
143-
* Test for Sanitize::sanitizeFilename
144-
*/
145-
public function testSanitizeFilename(): void
146+
#[DataProvider('providerTestSanitizeFileName')]
147+
public function testSanitizeFilename(string $expected, string $input, bool $replaceDot): void
146148
{
147-
self::assertSame(
148-
'File_name_123',
149-
Sanitize::sanitizeFilename('File_name 123'),
150-
);
149+
self::assertSame($expected, Sanitize::sanitizeFilename($input, $replaceDot));
150+
}
151+
152+
/** @return list<array{string,string,bool}> */
153+
public static function providerTestSanitizeFileName(): array
154+
{
155+
return [
156+
['Hello123', 'Hello123', false],
157+
['宮保雞丁', '宮保雞丁', false],
158+
['Україна', 'Україна', false],
159+
['-_-', '-.-', true],
160+
['-.-', '-.-', false],
161+
['___', '"\'"', false],
162+
['_test_', '<test>', false],
163+
['Hello__World_', "Hello\r\nWorld!", false],
164+
['_', "\u{fffd}", false],
165+
['_', '🚀', false],
166+
[str_repeat('_', 32), implode('', range("\0", "\x1f")), false],
167+
];
151168
}
152169

153170
/**

tests/unit/Server/PrivilegesTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,32 @@ public function testGetSqlQueriesForDisplayAndAddUserMySql8016(): void
730730
self::assertSame('CREATE USER \'PMA_username\'@\'PMA_hostname\' IDENTIFIED BY \'***\';', $createUserShow);
731731
}
732732

733+
public function testGetSqlQueriesForDisplayAndAddUserMySql8044EscapePw(): void
734+
{
735+
Config::getInstance()->selectedServer['DisableIS'] = false;
736+
737+
$dbi = $this->createDatabaseInterface();
738+
$dbi->setVersion(['@@version' => '8.0.44', '@@version_comment' => 'MySQL Community Server - GPL']);
739+
740+
$serverPrivileges = $this->getPrivileges($dbi);
741+
742+
$username = 'PMA_username';
743+
$hostname = 'PMA_hostname';
744+
$_POST['pred_password'] = 'userdefined';
745+
$_POST['pma_pw'] = 'pma_password\'';
746+
747+
[
748+
$createUserReal,
749+
$createUserShow,
750+
] = $serverPrivileges->getSqlQueriesForDisplayAndAddUser($username, $hostname, '');
751+
752+
//validate 1: $createUserReal
753+
self::assertSame("CREATE USER 'PMA_username'@'PMA_hostname' IDENTIFIED BY 'pma_password\\'';", $createUserReal);
754+
755+
//validate 2: $createUserShow
756+
self::assertSame("CREATE USER 'PMA_username'@'PMA_hostname' IDENTIFIED BY '***';", $createUserShow);
757+
}
758+
733759
public function testGetSqlQueriesForDisplayAndAddUserMySql50500AndUserDefinedPassword(): void
734760
{
735761
$dbiDummy = $this->createDbiDummy();

tests/unit/TypesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public static function providerForTestGetTypeDescription(): array
248248
['JSON'],
249249
['INET6'],
250250
['UUID'],
251+
['XMLTYPE'],
251252
];
252253
}
253254

0 commit comments

Comments
 (0)