Skip to content

fix: validate the stored language before using it (detectLang)#25

Open
Mubashirrrr wants to merge 1 commit into
revfactory:mainfrom
Mubashirrrr:fix/detectlang-validate-stored
Open

fix: validate the stored language before using it (detectLang)#25
Mubashirrrr wants to merge 1 commit into
revfactory:mainfrom
Mubashirrrr:fix/detectlang-validate-stored

Conversation

@Mubashirrrr
Copy link
Copy Markdown

What

detectLang() validates the URL-hash language but trusts the localStorage value unchecked, so a stale/invalid stored value leaves the page silently stuck in English.

Why

const hash = location.hash.replace('#', '').toLowerCase();
if (['en', 'ko', 'ja'].includes(hash)) return hash;   // validated
const stored = localStorage.getItem('harness-lang');
if (stored) return stored;                              // NOT validated

If harness-lang ever holds a value outside en|ko|ja (a future rename, a stale key, etc.), detectLang returns it, and setLang then fails every i18n[key][lang] lookup — leaving all text in English with no active language button — instead of falling through to the navigator.language / 'en' default.

Fix

Validate the stored value against the same allowed set as the hash path:

if (stored && ['en', 'ko', 'ja'].includes(stored)) return stored;

Small consistency/robustness fix; makes both code paths agree.

🤖 Generated with Claude Code

detectLang() validates the URL-hash language against ['en','ko','ja'] but
returns the localStorage value unchecked. A stale/invalid `harness-lang` value
would be handed to setLang(), which then no-ops every translation lookup
(leaving the page in English with no active language button) instead of falling
through to the navigator-language / 'en' default. Validate the stored value the
same way the hash path does.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant