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.
pull/7958/head
Frank Klaassen 4 months ago
parent f0f71536ab
commit c37c7fb933
No known key found for this signature in database

@ -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

Loading…
Cancel
Save