Commit 710bc55d authored by Thomas Löffler's avatar Thomas Löffler
Browse files

[TASK] Introduce ValidVersionService and check for valid versions when generating XML

parent eef1a6c8
Pipeline #20471 passed with stages
in 5 minutes and 37 seconds
......@@ -20,6 +20,7 @@ use T3o\Ter\Exception\NotFoundException;
use T3o\Ter\Exception\NoUploadCommentException;
use T3o\Ter\Exception\UnauthorizedException;
use T3o\TerFe2\Service\LTSVersionService;
use T3o\TerFe2\Service\ValidExtensionVersionService;
use T3o\TerFe2\Utility\ArchiveUtility;
use T3o\TerFe2\Utility\CategoryUtility;
use T3o\TerFe2\Utility\VersionUtility;
......@@ -99,7 +100,7 @@ class ExtensionVersion
*/
public function isValidVersionNumber(): bool
{
return (bool)preg_match('/^(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})$/', $this->version);
return ValidExtensionVersionService::isVersionStringValid($this->version);
// alternative (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $version) !== false) {
}
......
......@@ -123,6 +123,16 @@ class ExtensionIndexService implements LoggerAwareInterface
// Create the nested XML structure:
foreach ($extensionsAndVersionsArr as $extensionKey => $extensionVersionsArr) {
$extensionHasMinimumOneValidVersion = false;
foreach ($extensionVersionsArr['versions'] as $versionNumber => $extensionVersionArr) {
if (ValidExtensionVersionService::isVersionStringValid($versionNumber)) {
$extensionHasMinimumOneValidVersion = true;
break;
}
}
if (!$extensionHasMinimumOneValidVersion) {
continue;
}
$extensionObj = $extensionsObj->appendChild(new \DOMElement('extension'));
$extensionObj->appendChild(new \DOMAttr('extensionkey', $extensionKey));
$extensionObj->appendChild(
......@@ -133,6 +143,9 @@ class ExtensionIndexService implements LoggerAwareInterface
);
foreach ($extensionVersionsArr['versions'] as $versionNumber => $extensionVersionArr) {
if (!ValidExtensionVersionService::isVersionStringValid($versionNumber)) {
continue;
}
$versionObj = $extensionObj->appendChild(new \DOMElement('version'));
$versionObj->appendChild(new \DOMAttr('version', (string)$versionNumber));
$versionObj->appendChild(new \DOMElement('title', $this->xmlentities((string)$extensionVersionArr['title'])));
......
<?php
declare(strict_types = 1);
namespace T3o\TerFe2\Service;
final class ValidExtensionVersionService
{
public const VERSION_REGEX = '/^(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})$/';
public static function isVersionStringValid(string $versionString): bool
{
return (bool)preg_match(self::VERSION_REGEX, $versionString);
}
}
Supports Markdown
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