[PHP-WEBMASTER] [web-php] master: Only map to legacy URLs that use a language code instead of arbitrary text

Author: Derick Rethans (derickr)
Date: 2025-12-08T10:34:05Z

Commit: Only map to legacy URLs that use a language code instead of arbitrary… · php/web-php@2a1c9f6 · GitHub
Raw diff: https://github.com/php/web-php/commit/2a1c9f6acdf72c398bc5a5308252ad3473c26617.diff

Only map to legacy URLs that use a language code instead of arbitrary text

Changed paths:
  M include/errors.inc

Diff:

diff --git a/include/errors.inc b/include/errors.inc
index 76637c2dad..6bc9cf6c74 100644
--- a/include/errors.inc
+++ b/include/errors.inc
@@ -580,7 +580,7 @@ function get_legacy_manual_urls(string $uri): array
{
     $filename = $_SERVER["DOCUMENT_ROOT"] . "/manual/legacyurls.json";
     $pages_ids = json_decode(file_get_contents($filename), true);
- $page_id = preg_replace_callback('/^manual\/.*\/(.*?)(\.php)?$/', function (array $matches): string {
+ $page_id = preg_replace_callback('/^manual\/[a-z_A-Z]+\/(.*?)(\.php)?$/', function (array $matches): string {
         if (count($matches) < 2) {
             return '';
         }
@@ -611,7 +611,7 @@ function fallback_to_legacy_manuals(array $legacy_urls): void
     $original_url = htmlspecialchars(substr($MYSITE, 0, -1) . $_SERVER['REQUEST_URI']);
     $legacy_links = '';
     foreach ($legacy_urls as $php_version => $url) {
- $legacy_links .= '<li><a href="' . $url . '">PHP ' . $php_version . ' legacy manual</a></li>';
+ $legacy_links .= '<li><a href="' . htmlspecialchars($url) . '">PHP ' . $php_version . ' legacy manual</a></li>';
     }

     echo <<<HTML