Skip to content

fix(core): block disabling the default language pack#4813

Open
TowyTowy wants to merge 1 commit into
flarum:2.xfrom
TowyTowy:fix/default-language-pack-guard
Open

fix(core): block disabling the default language pack#4813
TowyTowy wants to merge 1 commit into
flarum:2.xfrom
TowyTowy:fix/default-language-pack-guard

Conversation

@TowyTowy

Copy link
Copy Markdown

Fixes #623 (re-opens the intent — the guard added for it never actually fires).

Changes proposed in this pull request

DefaultLanguagePackGuard is meant to stop an admin from disabling the language pack that default_locale points to. Its guard used in_array('flarum-locale', $extension->extra), which searches the values of the composer extra object — those values are arrays (branch-alias, flarum-extension, flarum-locale, …), so the string is never found, the check is always false, and the guard returns early. The protection was dead code: the default language pack could be disabled freely.

The very next line already treats flarum-locale as a key via Arr::get($extra, 'flarum-locale.code'), so this switches the check to Arr::has($extension->extra, 'flarum-locale').

Reviewers should focus on

  • DefaultLanguagePackGuard::handle() — the key-vs-value lookup.

Confirmed

  • Backend changes — added DB-free unit tests (tests/unit/Extension/DefaultLanguagePackGuardTest.php): default pack blocked, non-default pack allowed, non-language-pack extension allowed.
  • Frontend changes — N/A. Translations — N/A.

Testing

composer test:unit — the new tests fail before the change (exception not thrown) and pass after; full unit suite green (344 tests).

Prepared with AI assistance (Claude) and reviewed/verified by me.

DefaultLanguagePackGuard is meant to stop an admin from disabling the
language pack that `default_locale` points to, but its guard clause used
`in_array('flarum-locale', $extension->extra)`, which searches the
*values* of the composer `extra` object. Those values are arrays
(`branch-alias`, `flarum-extension`, `flarum-locale`, ...), so the string
is never found: the check is always false and the guard returned early,
leaving the protection as dead code -- the default language pack could be
disabled freely.

The next line already treats `flarum-locale` as a key via
`Arr::get($extra, 'flarum-locale.code')`, confirming a key lookup was
intended. Switch the guard to `Arr::has(..., 'flarum-locale')` so the
`PermissionDeniedException` fires when the default pack is disabled.

Add DB-free unit tests covering the default pack (blocked), a non-default
pack (allowed) and a non-language-pack extension (allowed).

Co-Authored-By: Claude <noreply@anthropic.com>
@TowyTowy TowyTowy requested a review from a team as a code owner July 13, 2026 12:18
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.

Check whether langpack is the default language before disabling

1 participant