Skip to content

Commit 7d9e370

Browse files
syphernlTrayshar
authored andcommitted
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. Cherry-picked from requarks/wiki requarks#7958
1 parent 1c576a3 commit 7d9e370

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

server/helpers/page.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,16 @@ module.exports = {
143143
}
144144
const result = localeFolderRegex.exec(meta.path)
145145
if (result[1]) {
146-
meta = {
147-
locale: result[1].replace('/', ''),
148-
path: result[2]
146+
const extractedLocale = result[1].replace('/', '')
147+
const knownLocales = new Set([
148+
WIKI.config.lang.code,
149+
...(WIKI.config.lang.namespaces || [])
150+
])
151+
if (knownLocales.has(extractedLocale)) {
152+
meta = {
153+
locale: extractedLocale,
154+
path: result[2]
155+
}
149156
}
150157
}
151158
return meta

0 commit comments

Comments
 (0)