Skip to content

fix: prevent 2-letter folder names from being misidentified as locale codes#7958

Open
syphernl wants to merge 1 commit intorequarks:mainfrom
syphernl:fix/locale-folder-false-positive
Open

fix: prevent 2-letter folder names from being misidentified as locale codes#7958
syphernl wants to merge 1 commit intorequarks:mainfrom
syphernl:fix/locale-folder-false-positive

Conversation

@syphernl
Copy link

Summary

Fix: validate the extracted locale candidate against the configured locales (WIKI.config.lang.code + WIKI.config.lang.namespaces) before accepting it. If not a known locale, the path segment is treated as part of the page path and the default locale is used.

Test plan

  • Create a page under a 2-letter folder (e.g. AI/some-page.md) in the Git repo and trigger a sync — page should import successfully
  • Create a page under a XX-YY hyphenated folder (e.g. CI-CD/page.md) — same
  • Verify pages under real locale folders (e.g. fr/page.md when fr is a configured namespace) still resolve correctly
  • Verify single-language setups (namespacing disabled) are unaffected

… 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.
@auto-assign auto-assign bot requested a review from NGPixel March 11, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants