diff --git a/app/vendor_config.php b/app/vendor_config.php index 49048be018..1970b4f868 100644 --- a/app/vendor_config.php +++ b/app/vendor_config.php @@ -24,7 +24,7 @@ return [ * Path to changelog file, can be gzip compressed. * Useful when you want to have documentation somewhere else, e.g. /usr/share/doc. */ - 'changeLogFile' => ROOT_PATH . 'ChangeLog', + 'changeLogFile' => ROOT_PATH . 'CHANGELOG-6.0.md', /** * Path to license file. Useful when you want to have documentation somewhere else, e.g. /usr/share/doc. diff --git a/bin/internal/check-release-excludes.sh b/bin/internal/check-release-excludes.sh index c7868cebbf..81913017de 100755 --- a/bin/internal/check-release-excludes.sh +++ b/bin/internal/check-release-excludes.sh @@ -146,6 +146,8 @@ validateExtension() { ;; ChangeLog) ;; + CHANGELOG-[5-9].[0-9].md) + ;; LICENSE) ;; RELEASE-DATE-[1-9].[0-9].[0-9]) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 01831e5927..2bfbf5d6e4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -701,6 +701,11 @@ + + + + + diff --git a/resources/templates/changelog.twig b/resources/templates/changelog.twig index 2a22d5ae86..b80e602623 100644 --- a/resources/templates/changelog.twig +++ b/resources/templates/changelog.twig @@ -9,7 +9,6 @@ phpMyAdmin - ChangeLog -

phpMyAdmin - ChangeLog

{{ changelog|raw }}
diff --git a/src/Controllers/ChangeLogController.php b/src/Controllers/ChangeLogController.php index 008777eb12..2498a0161a 100644 --- a/src/Controllers/ChangeLogController.php +++ b/src/Controllers/ChangeLogController.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Template; use PhpMyAdmin\Url; use function __; +use function array_column; use function array_keys; use function basename; use function file_get_contents; @@ -22,19 +23,23 @@ use function htmlspecialchars; use function is_readable; use function ob_get_clean; use function ob_start; +use function preg_match_all; use function preg_replace; +use function preg_replace_callback; use function readgzfile; use function sprintf; use function str_ends_with; +use const PREG_SET_ORDER; + #[Route('/changelog', ['GET'])] -final class ChangeLogController implements InvocableController +final readonly class ChangeLogController implements InvocableController { public function __construct( - private readonly ResponseRenderer $response, - private readonly Config $config, - private readonly ResponseFactory $responseFactory, - private readonly Template $template, + private ResponseRenderer $response, + private Config $config, + private ResponseFactory $responseFactory, + private Template $template, ) { } @@ -77,42 +82,46 @@ final class ChangeLogController implements InvocableController $githubUrl = 'https://github.com/phpmyadmin/phpmyadmin/'; $faqUrl = 'https://docs.phpmyadmin.net/en/latest/faq.html'; - $replaces = [ - '@(https?://[./a-zA-Z0-9.-_-]*[/a-zA-Z0-9_])@' => '\\1', + preg_match_all('@\n\[(\d+\.\d+\.\d+)]: (' . $githubUrl . '\S+)@', $changelog, $matches, PREG_SET_ORDER); + $releaseLinks = array_column($matches, 2, 1); + $changelog = (string) preg_replace_callback( + '/\n## \[(\d+\.\d+\.\d+)]/', + static fn (array $matches): string => "\n## [" . $matches[1] . '](' . $releaseLinks[$matches[1]] . ')', + $changelog, + ); - // mail address - '/([0-9]{4}-[0-9]{2}-[0-9]{2}) (.+[^ ]) +<(.*@.*)>/i' => '\\1 \\2', + $replaces = [ + '/# Changes in phpMyAdmin (\d+\.\d+)/' => '

Changes in phpMyAdmin \\1

', + '@\[Keep a Changelog\]\(https://keepachangelog.com/\)@' => 'Keep a Changelog', + '/\n### (Added|Changed|Deprecated|Removed|Fixed|Security)/' => "\n" . '

\\1

', + + // Add link to release title + '@\n## \[(\d+\.\d+\.\d+)\]\((' . $githubUrl . '\S+)\) \- (\d{4}|YYYY)-(\d{2}|MM)-(\d{2}|DD)\n@' => "\n" + . '

\\1 \\3-\\4-\\5

' . "\n", + + // Add link to GitHub issues/commits + '@\[(\#\d+|[a-z0-9]+)\]\((' . $githubUrl . '\S+)\)@' => '\\1', // FAQ entries '/FAQ ([0-9]+)\.([0-9a-z]+)/i' => 'FAQ \\1.\\2', - // GitHub issues - '/issue\s*#?([0-9]{4,5}) /i' => 'issue #\\1 ', - // CVE/CAN entries '/((CAN|CVE)-[0-9]+-[0-9]+)/' => '\\1', - // PMASAentries + // PMASA entries '/(PMASA-[0-9]+-[0-9]+)/' => '\\1', - // Highlight releases (with links) - '/([0-9]+)\.([0-9]+)\.([0-9]+)\.0 (\([0-9-]+\))/' => '' - . '' - . '\\1.\\2.\\3.0 \\4', - '/([0-9]+)\.([0-9]+)\.([0-9]+)\.([1-9][0-9]*) (\([0-9-]+\))/' => '' - . '' - . '\\1.\\2.\\3.\\4 \\5', - - // Highlight releases (not linkable) - '/( ### )(.*)/' => '\\1\\2', - // Links target and rel '/a href="/' => 'a target="_blank" rel="noopener noreferrer" href="', + + // Remove release link references + '@\n\[(\d+\.\d+\.\d+)]: (' . $githubUrl . '\S+)@' => '', + + '/YYYY-MM-DD/' => '(not yet released)', ]; return $response->write($this->template->render('changelog', [ diff --git a/tests/test_data/changelog/CHANGELOG-5.2.md b/tests/test_data/changelog/CHANGELOG-5.2.md new file mode 100644 index 0000000000..a3f00f6b84 --- /dev/null +++ b/tests/test_data/changelog/CHANGELOG-5.2.md @@ -0,0 +1,48 @@ +# Changes in phpMyAdmin 5.2 + +All notable changes of the phpMyAdmin 5.2 release series are documented in this file following the [Keep a Changelog](https://keepachangelog.com/) format. + +## [5.2.2] - YYYY-MM-DD + +### Fixed + +* [#17522](https://github.com/phpmyadmin/phpmyadmin/issues/17522): Fix case where the routes cache file is invalid + +### Security + +* Upgrade slim/psr7 to 1.4.1 for CVE-2023-30536 - GHSA-q2qj-628g-vhfw + +## [5.2.1] - 2023-02-07 + +### Added + +* [#17519](https://github.com/phpmyadmin/phpmyadmin/issues/17519): Fix Export pages not working in certain conditions +* [#17496](https://github.com/phpmyadmin/phpmyadmin/issues/17496): Fix error in table operation page when partitions are broken + +### Changed + +* [#17519](https://github.com/phpmyadmin/phpmyadmin/issues/17519): Fix Export pages not working in certain conditions +* [#17496](https://github.com/phpmyadmin/phpmyadmin/issues/17496): Fix error in table operation page when partitions are broken + +### Deprecated + +* [#17519](https://github.com/phpmyadmin/phpmyadmin/issues/17519): Fix Export pages not working in certain conditions +* [#17496](https://github.com/phpmyadmin/phpmyadmin/issues/17496): Fix error in table operation page when partitions are broken + +### Removed + +* [#17519](https://github.com/phpmyadmin/phpmyadmin/issues/17519): Fix Export pages not working in certain conditions +* [#17496](https://github.com/phpmyadmin/phpmyadmin/issues/17496): Fix error in table operation page when partitions are broken + +### Fixed + +* [#17519](https://github.com/phpmyadmin/phpmyadmin/issues/17519): Fix Export pages not working in certain conditions +* [#17496](https://github.com/phpmyadmin/phpmyadmin/issues/17496): Fix error in table operation page when partitions are broken +* [#16418](https://github.com/phpmyadmin/phpmyadmin/issues/16418): Fix FAQ 1.44 about manually removing vendor folders + +### Security + +* Fix an XSS attack through the drag-and-drop upload feature (PMASA-2023-01) + +[5.2.2]: https://github.com/phpmyadmin/phpmyadmin/compare/RELEASE_5_2_1...QA_5_2 +[5.2.1]: https://github.com/phpmyadmin/phpmyadmin/compare/RELEASE_5_2_0...RELEASE_5_2_1 diff --git a/tests/test_data/changelog/CHANGELOG-5.2.md.gz b/tests/test_data/changelog/CHANGELOG-5.2.md.gz new file mode 100644 index 0000000000..031cdabfd4 Binary files /dev/null and b/tests/test_data/changelog/CHANGELOG-5.2.md.gz differ diff --git a/tests/test_data/changelog/ChangeLog b/tests/test_data/changelog/ChangeLog deleted file mode 100644 index 7fd6557b1e..0000000000 --- a/tests/test_data/changelog/ChangeLog +++ /dev/null @@ -1,13 +0,0 @@ -phpMyAdmin - ChangeLog -====================== - -5.2.2 (not yet released) -- issue #17522 Fix case where the routes cache file is invalid -- issue Upgrade slim/psr7 to 1.4.1 for CVE-2023-30536 - GHSA-q2qj-628g-vhfw - -5.2.1 (2023-02-07) -- issue #16418 Fix FAQ 1.44 about manually removing vendor folders -- issue [security] Fix an XSS attack through the drag-and-drop upload feature (PMASA-2023-01) - - --- Older ChangeLogs can be found on our project website --- - https://www.phpmyadmin.net/old-stuff/ChangeLogs/ diff --git a/tests/test_data/changelog/ChangeLog.gz b/tests/test_data/changelog/ChangeLog.gz deleted file mode 100644 index c8be7d6bd2..0000000000 Binary files a/tests/test_data/changelog/ChangeLog.gz and /dev/null differ diff --git a/tests/unit/Controllers/ChangeLogControllerTest.php b/tests/unit/Controllers/ChangeLogControllerTest.php index 415a5d920f..90073932ae 100644 --- a/tests/unit/Controllers/ChangeLogControllerTest.php +++ b/tests/unit/Controllers/ChangeLogControllerTest.php @@ -20,10 +20,21 @@ final class ChangeLogControllerTest extends AbstractTestCase { public function testWithValidFile(): void { - $config = self::createStub(Config::class); - $config->method('getChangeLogFilePath')->willReturn(__DIR__ . '/../../test_data/changelog/ChangeLog'); + $this->assertChangelogOutputIsValid(__DIR__ . '/../../test_data/changelog/CHANGELOG-5.2.md'); + } - $request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/'); + #[RequiresPhpExtension('zlib')] + public function testWithCompressedFile(): void + { + $this->assertChangelogOutputIsValid(__DIR__ . '/../../test_data/changelog/CHANGELOG-5.2.md.gz'); + } + + private function assertChangelogOutputIsValid(string $changelogPath): void + { + $config = self::createStub(Config::class); + $config->method('getChangeLogFilePath')->willReturn($changelogPath); + + $request = ServerRequestFactory::create()->createServerRequest('GET', 'https://example.com/'); $responseRenderer = new ResponseRenderer(); $template = new Template(); @@ -35,19 +46,52 @@ final class ChangeLogControllerTest extends AbstractTestCase // phpcs:disable Generic.Files.LineLength.TooLong $changelog = <<<'HTML' - phpMyAdmin - ChangeLog - ====================== +

Changes in phpMyAdmin 5.2

- 5.2.2 (not yet released) - - issue #17522 Fix case where the routes cache file is invalid - - issue Upgrade slim/psr7 to 1.4.1 for CVE-2023-30536 - GHSA-q2qj-628g-vhfw + All notable changes of the phpMyAdmin 5.2 release series are documented in this file following the Keep a Changelog format. - 5.2.1 (2023-02-07) - - issue #16418 Fix FAQ 1.44 about manually removing vendor folders - - issue [security] Fix an XSS attack through the drag-and-drop upload feature (PMASA-2023-01) +

5.2.2 (not yet released)

+ +

Fixed

+ + * #17522: Fix case where the routes cache file is invalid + +

Security

+ + * Upgrade slim/psr7 to 1.4.1 for CVE-2023-30536 - GHSA-q2qj-628g-vhfw + +

5.2.1 2023-02-07

+ +

Added

+ + * #17519: Fix Export pages not working in certain conditions + * #17496: Fix error in table operation page when partitions are broken + +

Changed

+ + * #17519: Fix Export pages not working in certain conditions + * #17496: Fix error in table operation page when partitions are broken + +

Deprecated

+ + * #17519: Fix Export pages not working in certain conditions + * #17496: Fix error in table operation page when partitions are broken + +

Removed

+ + * #17519: Fix Export pages not working in certain conditions + * #17496: Fix error in table operation page when partitions are broken + +

Fixed

+ + * #17519: Fix Export pages not working in certain conditions + * #17496: Fix error in table operation page when partitions are broken + * #16418: Fix FAQ 1.44 about manually removing vendor folders + +

Security

+ + * Fix an XSS attack through the drag-and-drop upload feature (PMASA-2023-01) - --- Older ChangeLogs can be found on our project website --- - https://www.phpmyadmin.net/old-stuff/ChangeLogs/ HTML; // phpcs:enable @@ -56,36 +100,12 @@ final class ChangeLogControllerTest extends AbstractTestCase self::assertSame($expected, (string) $response->getBody()); } - #[RequiresPhpExtension('zlib')] - public function testWithCompressedFile(): void - { - $config = self::createStub(Config::class); - $config->method('getChangeLogFilePath')->willReturn(__DIR__ . '/../../test_data/changelog/ChangeLog.gz'); - - $request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/'); - - $responseRenderer = new ResponseRenderer(); - $controller = new ChangeLogController($responseRenderer, $config, ResponseFactory::create(), new Template()); - $response = $controller($request); - - self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); - self::assertSame(['text/html; charset=utf-8'], $response->getHeader('Content-Type')); - self::assertStringContainsString( - '- ' - . 'issue #16418 Fix ' - . 'FAQ 1.44 about manually removing vendor folders', - (string) $response->getBody(), - ); - } - public function testWithInvalidFile(): void { $config = self::createStub(Config::class); $config->method('getChangeLogFilePath')->willReturn(__DIR__ . '/../../test_data/changelog/InvalidChangeLog'); - $request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/'); + $request = ServerRequestFactory::create()->createServerRequest('GET', 'https://example.com/'); $responseRenderer = new ResponseRenderer(); $controller = new ChangeLogController($responseRenderer, $config, ResponseFactory::create(), new Template());