From 7c120a10bf24dcedb756a900668f08ace18bb5c9 Mon Sep 17 00:00:00 2001 From: William Jacoby Date: Thu, 12 Nov 2026 19:37:56 -0600 Subject: [PATCH 1/2] Fix link-box contrast, legacy migration steps and tests that only pass together - The article link boxes used #2e8b57 on white (4.25:1); they now use #237047 (6:1). - The stylesheet route's 404 carries no hard-coded English text. - version_1_0_0 listed every allowed file extension twice, once per column of the row, and read undefined variables when no extension group was allowed; it now lists each once. It drops the old kb_config.is_dynamic column through phpBB's database tools, which also handle MSSQL, instead of a plain DROP COLUMN. - version_2_0_1 unserializes the old kb_extensions setting without creating objects. - Four test files depended on other tests loading phpBB's utf_tools.php or functions_kb.php and failed, or exited silently, when run alone. - New tests: the legacy steps on SQLite, MySQL and PostgreSQL, an object in the old setting, the empty 404 body, and the link-box contrast in kb_form_access.js. Co-Authored-By: Claude Opus 5.5 --- controller/stylesheet.php | 7 +- migrations/version_1_0_0.php | 32 +--- migrations/version_2_0_1.php | 3 +- .../all/theme/phpbbmodders_knowledgebase.css | 3 +- tests/browser/kb_form_access.js | 16 +- tests/kb_alternative_style_test.php | 3 + tests/kb_article_text_test.php | 2 + tests/kb_board_search_test.php | 2 + tests/kb_legacy_migration_test.php | 158 ++++++++++++++++++ tests/kb_recent_changes_test.php | 1 + 10 files changed, 198 insertions(+), 29 deletions(-) create mode 100644 tests/kb_legacy_migration_test.php diff --git a/controller/stylesheet.php b/controller/stylesheet.php index b10ffc7..10523c1 100644 --- a/controller/stylesheet.php +++ b/controller/stylesheet.php @@ -41,14 +41,15 @@ public function __construct(alternative_styles $alt_styles, request $request) /** * The stylesheet named by the "f" query parameter. * - * @return Response The CSS, a 304 when the browser's copy is current, or a 404 + * @return Response The CSS, a 304 when the browser's copy is current, or an empty 404 + * (a stylesheet request is never shown, so it carries no text) */ public function serve(): Response { $path = $this->alt_styles->custom_file_path($this->request->variable('f', '')); if ($path === null) { - return new Response('Not found', 404, ['Content-Type' => 'text/plain; charset=UTF-8']); + return new Response('', 404, ['Content-Type' => 'text/plain; charset=UTF-8']); } $modified = (int) filemtime($path); @@ -72,7 +73,7 @@ public function serve(): Response $css = file_get_contents($path); return $css === false - ? new Response('Not found', 404, ['Content-Type' => 'text/plain; charset=UTF-8']) + ? new Response('', 404, ['Content-Type' => 'text/plain; charset=UTF-8']) : new Response($css, 200, $headers); } } diff --git a/migrations/version_1_0_0.php b/migrations/version_1_0_0.php index 2795b9d..51c434f 100644 --- a/migrations/version_1_0_0.php +++ b/migrations/version_1_0_0.php @@ -347,32 +347,14 @@ public function set_default_config() WHERE e.group_id = g.group_id AND g.allow_group = 1'; $result = $this->db->sql_query($sql); + // Each allowed extension once, under its group's name + $xt = []; while ($row = $this->db->sql_fetchrow($result)) { - $extensions[] = $row; + $xt[$row['group_name']][] = $row['extension']; } $this->db->sql_freeresult($result); - foreach ($extensions as $extension) - { - $names[] = $extension['group_name']; - } - $names = array_values(array_unique($names)); - - foreach ($extensions as $extension) - { - foreach ($names as $name) - { - foreach ($extension as $ext) - { - if ($extension['group_name'] == $name) - { - $xt[$name][] = $extension['extension']; - } - } - } - } - $extensions = serialize($xt); $sql = 'SELECT config_value @@ -407,8 +389,12 @@ public function set_default_config() } else { - $sql = 'ALTER TABLE ' . $this->table_prefix . 'kb_config DROP COLUMN is_dynamic'; - $this->db->sql_query($sql); + // phpBB's database tools, which also drop the column's default + // constraint first on MSSQL, where a plain DROP COLUMN fails + if ($this->db_tools->sql_column_exists($this->table_prefix . 'kb_config', 'is_dynamic')) + { + $this->db_tools->sql_column_remove($this->table_prefix . 'kb_config', 'is_dynamic'); + } // MySQL-specific CHANGE/CHARACTER SET syntax - only meaningful (and // only valid) on a MySQL-family driver; other DBMS keep whatever // collation the column already had, which is harmless here. diff --git a/migrations/version_2_0_1.php b/migrations/version_2_0_1.php index 99a84a2..8539769 100644 --- a/migrations/version_2_0_1.php +++ b/migrations/version_2_0_1.php @@ -45,7 +45,8 @@ public function update_data() if (!str_starts_with($extensions, '{')) { - $extensions = json_encode(unserialize($extensions)); + // The old setting holds only arrays and strings, so objects are refused + $extensions = json_encode(unserialize($extensions, ['allowed_classes' => false])); } return [ diff --git a/styles/all/theme/phpbbmodders_knowledgebase.css b/styles/all/theme/phpbbmodders_knowledgebase.css index e85339c..33bb2d8 100644 --- a/styles/all/theme/phpbbmodders_knowledgebase.css +++ b/styles/all/theme/phpbbmodders_knowledgebase.css @@ -112,7 +112,8 @@ dd.action { .kb_codebox code { font: 105% Monaco, "Andale Mono", "Courier New", Courier, monospace; - color: #2e8b57; + /* A darker green than prosilver's #2e8b57 (4.25:1 on white), which passes WCAG AA at 6:1 */ + color: #237047; display: inline-block; overflow: auto; margin-bottom: -5px; diff --git a/tests/browser/kb_form_access.js b/tests/browser/kb_form_access.js index 6c42fef..83631be 100644 --- a/tests/browser/kb_form_access.js +++ b/tests/browser/kb_form_access.js @@ -5,7 +5,8 @@ // - the custom-field filter and the "drafts only" box have a Go button when // JavaScript is off (both normally submit on change); // - no field on the add-article form, nor the ACP field type menu, has more than one label; -// - the inactive tabs' text passes WCAG AA contrast (4.5:1) on its background; +// - the inactive tabs' text and the article link boxes pass WCAG AA contrast +// (4.5:1) on their background; // - article title links and the queue's buttons and menus are at least 24px // high on a phone. // Read-only: it submits nothing but the login forms. @@ -109,6 +110,19 @@ function contrast(fore, back) { const weak = tabs.filter(([, fore, back]) => !/rgba\(0, 0, 0, 0\)/.test(back) && contrast(fore, back) < 4.5); record('inactive tabs pass 4.5:1 contrast', tabs.length > 0 && weak.length === 0, weak.map(([text]) => text).join(', ')); + // The link boxes on an article: their text on the nearest painted background + await js.goto(`${base}/app.php/knowledgebase/article?k=1`, ready); + const boxes = await js.locator('.kb_codebox code').evaluateAll(codes => codes.map(code => { + let element = code, back = 'rgba(0, 0, 0, 0)'; + while (element && /rgba\(0, 0, 0, 0\)|transparent/.test(back)) { + back = getComputedStyle(element).backgroundColor; + element = element.parentElement; + } + return [getComputedStyle(code).color, back]; + })); + const faint = boxes.filter(([fore, back]) => contrast(fore, back) < 4.5); + record('article link boxes pass 4.5:1 contrast', boxes.length > 0 && faint.length === 0, faint.map(([fore]) => fore).join(', ')); + // Touch targets on a phone: article title links, and the queue's buttons and menus await js.setViewportSize({width: 375, height: 812}); const small = []; diff --git a/tests/kb_alternative_style_test.php b/tests/kb_alternative_style_test.php index 4f3219c..ecaafa9 100644 --- a/tests/kb_alternative_style_test.php +++ b/tests/kb_alternative_style_test.php @@ -12,6 +12,8 @@ namespace phpbbmodders\knowledgebase\controller; require_once __DIR__ . '/kb_extensions_test.php'; +if (!defined('IN_PHPBB')) define('IN_PHPBB', true); +require_once (getenv('PHPBB_ROOT_PATH') ?: dirname(__DIR__, 4)) . '/includes/utf/utf_tools.php'; require_once dirname(__DIR__) . '/inc/alternative_styles.php'; require_once dirname(__DIR__) . '/controller/stylesheet.php'; require_once dirname(__DIR__) . '/event/listener.php'; @@ -344,6 +346,7 @@ public function test_nothing_unsafe_is_ever_served(string $name) $this->assertSame(404, $response->getStatusCode()); $this->assertStringNotContainsString('secret', $response->getContent()); + $this->assertSame('', $response->getContent()); $this->assertSame('text/plain; charset=UTF-8', $response->headers->get('Content-Type')); } diff --git a/tests/kb_article_text_test.php b/tests/kb_article_text_test.php index da6d46b..882cab1 100644 --- a/tests/kb_article_text_test.php +++ b/tests/kb_article_text_test.php @@ -11,6 +11,8 @@ namespace phpbbmodders\knowledgebase\textformatter; require_once __DIR__ . '/kb_extensions_test.php'; +if (!defined('IN_PHPBB')) define('IN_PHPBB', true); +require_once (getenv('PHPBB_ROOT_PATH') ?: dirname(__DIR__, 4)) . '/includes/utf/utf_tools.php'; require_once dirname(__DIR__) . '/textformatter/article_text.php'; if (!defined('OPTION_FLAG_BBCODE')) define('OPTION_FLAG_BBCODE', 1); diff --git a/tests/kb_board_search_test.php b/tests/kb_board_search_test.php index eb98330..a5c7079 100644 --- a/tests/kb_board_search_test.php +++ b/tests/kb_board_search_test.php @@ -12,6 +12,8 @@ namespace phpbbmodders\knowledgebase; require_once __DIR__ . '/kb_extensions_test.php'; +if (!defined('IN_PHPBB')) define('IN_PHPBB', true); +require_once (getenv('PHPBB_ROOT_PATH') ?: dirname(__DIR__, 4)) . '/includes/utf/utf_tools.php'; require_once dirname(__DIR__) . '/inc/functions_kb.php'; require_once dirname(__DIR__) . '/inc/board_search.php'; require_once dirname(__DIR__) . '/textformatter/article_text.php'; diff --git a/tests/kb_legacy_migration_test.php b/tests/kb_legacy_migration_test.php new file mode 100644 index 0000000..3ed3f4b --- /dev/null +++ b/tests/kb_legacy_migration_test.php @@ -0,0 +1,158 @@ +tools instanceof \phpbb\db\tools\doctrine) $this->tools->get_connection()->close(); + if ($this->db) $this->db->sql_close(); + if ($this->sqlite_fixture) @unlink($this->sqlite_fixture); + } + + public function engines() + { + return [['sqlite'], ['mysql'], ['postgres']]; + } + + private function connect(string $engine): void + { + if ($engine === 'sqlite') + { + $this->db = new \phpbb\db\driver\sqlite3(); + if (class_exists(\phpbb\db\tools\doctrine::class)) + { + $this->sqlite_fixture = tempnam(sys_get_temp_dir(), 'kb-legacy-'); + $this->assertTrue($this->db->sql_connect($this->sqlite_fixture, '', '', '')); + $this->tools = new \phpbb\db\tools\doctrine(\phpbb\db\doctrine\connection_factory::get_connection_from_params('sqlite3', $this->sqlite_fixture)); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); + $this->tools = new \phpbb\db\tools\sqlite3($this->db); + } + return; + } + + $port = getenv('KB_TEST_' . strtoupper($engine) . '_PORT'); + if (!$port) $this->markTestSkipped('Set the fixture database port to run integration tests'); + $this->assertTrue(ctype_digit($port)); + $this->db = $engine === 'mysql' ? new \phpbb\db\driver\mysqli() : new \phpbb\db\driver\postgres(); + $this->assertIsObject($this->db->sql_connect('127.0.0.1', $engine === 'mysql' ? 'root' : 'postgres', '', 'kb_fixture', (int) $port)); + if (class_exists(\phpbb\db\tools\doctrine::class)) + { + $this->tools = new \phpbb\db\tools\doctrine(\phpbb\db\doctrine\connection_factory::get_connection_from_params( + $engine === 'mysql' ? 'mysqli' : 'postgres', '127.0.0.1', $engine === 'mysql' ? 'root' : 'postgres', '', 'kb_fixture', $port + )); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->tools = $engine === 'mysql' ? new \phpbb\db\tools\tools($this->db) : new \phpbb\db\tools\postgres($this->db); + } + } + + /** @dataProvider engines */ + public function test_the_old_settings_table_loses_is_dynamic_and_gets_the_new_settings($engine) + { + $this->connect($engine); + $tables = ['phpbb_kb_config', 'phpbb_extensions', 'phpbb_extension_groups', 'phpbb_config']; + foreach ($tables as $table) + { + if ($this->tools->sql_table_exists($table)) $this->tools->sql_table_drop($table); + } + + // The tables set_default_config() reads, as an older Knowledge Base left them + $this->tools->sql_create_table('phpbb_extension_groups', ['COLUMNS' => ['group_id' => ['UINT', 0], 'group_name' => ['VCHAR', ''], 'allow_group' => ['BOOL', 0]]]); + $this->tools->sql_create_table('phpbb_extensions', ['COLUMNS' => ['group_id' => ['UINT', 0], 'extension' => ['VCHAR:100', '']]]); + $this->tools->sql_create_table('phpbb_config', ['COLUMNS' => ['config_name' => ['VCHAR', ''], 'config_value' => ['VCHAR_UNI', '']]]); + $this->tools->sql_create_table('phpbb_kb_config', ['COLUMNS' => [ + 'config_name' => ['VCHAR', ''], + 'config_value' => ['TEXT_UNI', ''], + 'is_dynamic' => ['BOOL', 0], + ]]); + $this->db->sql_query("INSERT INTO phpbb_extension_groups (group_id, group_name, allow_group) VALUES (1, 'IMAGES', 1)"); + $this->db->sql_query("INSERT INTO phpbb_extensions (group_id, extension) VALUES (1, 'png')"); + $this->db->sql_query("INSERT INTO phpbb_config (config_name, config_value) VALUES ('max_filesize', '262144')"); + $this->db->sql_query("INSERT INTO phpbb_kb_config (config_name, config_value, is_dynamic) VALUES ('anounce', '1', 0)"); + + $migration = new version_1_0_0(new \phpbb\config\config([]), $this->db, $this->tools, '', 'php', 'phpbb_', []); + $migration->set_default_config(); + + $this->assertFalse($this->tools->sql_column_exists('phpbb_kb_config', 'is_dynamic')); + $result = $this->db->sql_query('SELECT config_name, config_value FROM phpbb_kb_config'); + $settings = []; + while ($row = $this->db->sql_fetchrow($result)) + { + $settings[$row['config_name']] = $row['config_value']; + } + $this->db->sql_freeresult($result); + $this->assertSame('1', $settings['anounce']); + $this->assertSame('262144', $settings['max_filesize']); + $this->assertSame(['IMAGES' => ['png']], unserialize($settings['extensions'])); + + foreach ($tables as $table) + { + $this->tools->sql_table_drop($table); + } + } + + public function test_the_serialized_extensions_setting_creates_no_object() + { + kb_legacy_wakeup_probe::$woken = false; + $stored = serialize(['IMAGES' => ['png', 'gif'], 'evil' => new kb_legacy_wakeup_probe()]); + + $db = $this->createMock(\phpbb\db\driver\driver_interface::class); + $db->method('sql_query')->willReturn(true); + $db->method('sql_fetchrow')->willReturn(['config_value' => $stored]); + $migration = new version_2_0_1(new \phpbb\config\config([]), $db, $this->createMock(\phpbb\db\tools\tools_interface::class), '', 'php', 'phpbb_', []); + + $steps = $migration->update_data(); + + $this->assertFalse(kb_legacy_wakeup_probe::$woken); + $this->assertSame('config_text.update', $steps[0][0]); + $converted = json_decode($steps[0][1][1], true); + $this->assertSame(['png', 'gif'], $converted['IMAGES']); + $this->assertArrayNotHasKey('woken', $converted['evil']); + } +} + +/** + * A class whose __wakeup() records that unserialize() created it + */ +class kb_legacy_wakeup_probe +{ + public static $woken = false; + + public function __wakeup() + { + self::$woken = true; + } +} diff --git a/tests/kb_recent_changes_test.php b/tests/kb_recent_changes_test.php index 939c7a1..c32f901 100644 --- a/tests/kb_recent_changes_test.php +++ b/tests/kb_recent_changes_test.php @@ -12,6 +12,7 @@ namespace phpbbmodders\knowledgebase; require_once __DIR__ . '/kb_extensions_test.php'; +require_once dirname(__DIR__) . '/inc/functions_kb.php'; require_once dirname(__DIR__) . '/inc/feed.php'; require_once dirname(__DIR__) . '/migrations/version_2_0_29.php'; require_once dirname(__DIR__) . '/controller/recent_changes.php'; From fbf49e4fb9c4e83fb9c5a696f178f3992c627ee8 Mon Sep 17 00:00:00 2001 From: William Jacoby Date: Thu, 12 Nov 2026 19:40:58 -0600 Subject: [PATCH 2/2] Document the link-box, legacy migration and test fixes Co-Authored-By: Claude Opus 5.5 --- .github/epv-allowed.txt | 3 ++- docs/testing.md | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/epv-allowed.txt b/.github/epv-allowed.txt index 6ddb5b3..384831b 100644 --- a/.github/epv-allowed.txt +++ b/.github/epv-allowed.txt @@ -25,7 +25,8 @@ Error: Using addslashes in /controller/posting.php Error: Using addslashes in /inc/functions_kb.php # Released migration: converts the old serialized kb_extensions setting to -# JSON once. Released migrations must not be changed. +# JSON once, refusing objects (allowed_classes false). EPV flags any +# unserialize() call. Error: Using unserialize in /migrations/version_2_0_1.php # Released migrations without anything to revert: version_2_0_0 moves the diff --git a/docs/testing.md b/docs/testing.md index 8a96bc4..273bef8 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1666,3 +1666,26 @@ administrator in the first category, which fails with an SQL error on the old co with two of the administrator's groups set to NEVER, the trace shows every row in words. Claude ran the sweep (27 of 27) and `kb_form_access.js` (9 of 9) on the phpBB 3.3.19 and 4.0.0-a3-dev SQLite boards. + +## Link-box contrast, legacy migration steps and stand-alone tests - 11/12/2026 + +- The article link boxes used `#2e8b57` on white, 4.25:1; they now use `#237047`, about 6:1. + `tests/browser/kb_form_access.js` checks it (10 checks now); the check fails on the old colour. +- The stylesheet route answers a missing file with an empty 404 instead of English text. +- `version_1_0_0`'s `set_default_config()` listed every allowed file extension twice (once per + column of the query's row) and read undefined variables when no extension group was allowed. It + now lists each extension once. Its step for boards with an older settings table drops + `kb_config.is_dynamic` through phpBB's database tools, which also remove the column's default on + MSSQL first, instead of a plain `ALTER TABLE ... DROP COLUMN`. +- `version_2_0_1` unserializes the old `kb_extensions` setting with `allowed_classes => false`. +- `kb_alternative_style_test.php`, `kb_article_text_test.php`, `kb_board_search_test.php` and + `kb_recent_changes_test.php` used phpBB's `utf_tools.php` or `functions_kb.php` without loading + them, so they failed (or stopped silently, since `utf_tools.php` exits without `IN_PHPBB`) when + run alone. Every test file now passes on its own as well as in the suite. + +`tests/kb_legacy_migration_test.php` runs the old-settings step on SQLite, MySQL and PostgreSQL and +checks that an object in the old setting is never created. Claude ran the PHPUnit suite on phpBB +3.3.x and master with the MySQL and PostgreSQL fixtures (586 tests, none skipped), every test file +alone, EPV on both branches and phpcs, and `kb_form_access.js` (10 of 10) and `kb_page_sweep.js` +(27 of 27) on phpBB 3.3.19 and 4.0.0-a3-dev SQLite boards. +