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 6 months ago
parent f0f71536ab
commit c37c7fb933
No known key found for this signature in database

@ -143,11 +143,18 @@ module.exports = {
} }
const result = localeFolderRegex.exec(meta.path) const result = localeFolderRegex.exec(meta.path)
if (result[1]) { if (result[1]) {
const extractedLocale = result[1].replace('/', '')
const knownLocales = new Set([
WIKI.config.lang.code,
...(WIKI.config.lang.namespaces || [])
])
if (knownLocales.has(extractedLocale)) {
meta = { meta = {
locale: result[1].replace('/', ''), locale: extractedLocale,
path: result[2] path: result[2]
} }
} }
}
return meta return meta
} }
} }

Loading…
Cancel
Save