From c37c7fb933cce3ae2cf082643bcb79d382fdca56 Mon Sep 17 00:00:00 2001 From: Frank Klaassen <639906+syphernl@users.noreply.github.com> Date: Wed, 11 Mar 2026 15:40:21 +0100 Subject: [PATCH] fix: prevent 2-letter folder names from being misidentified as locale codes getPagePath() used a regex to extract locale prefixes from file paths, but any top-level folder with a 2-letter name (e.g. AI/, CI/) or 2+2-letter hyphenated name (e.g. CI-CD/) matched the BCP 47 locale pattern, causing the extracted non-existent locale to violate the pages_localecode_foreign FK constraint on insert. Now validates the extracted locale against the configured locales (WIKI.config.lang.code + WIKI.config.lang.namespaces) before accepting it. --- server/helpers/page.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/helpers/page.js b/server/helpers/page.js index 8bea0aa3b..652012c2e 100644 --- a/server/helpers/page.js +++ b/server/helpers/page.js @@ -143,9 +143,16 @@ module.exports = { } const result = localeFolderRegex.exec(meta.path) if (result[1]) { - meta = { - locale: result[1].replace('/', ''), - path: result[2] + const extractedLocale = result[1].replace('/', '') + const knownLocales = new Set([ + WIKI.config.lang.code, + ...(WIKI.config.lang.namespaces || []) + ]) + if (knownLocales.has(extractedLocale)) { + meta = { + locale: extractedLocale, + path: result[2] + } } } return meta