Skip to content

fix(persistence): strict type validation for location/weather from localStorage#5

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/sub-pr-2
Draft

fix(persistence): strict type validation for location/weather from localStorage#5
Copilot wants to merge 2 commits intomainfrom
copilot/sub-pr-2

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 24, 2026

Truthiness checks on parsed.location and parsed.weather allowed falsy invalid values ('', 0, false) to bypass validation and persist into app state.

Changes

  • src/lib/core/persistence.ts: Replace truthiness guards with !== undefined + explicit typeof === 'string' checks before set/array membership tests; delete the key on any type mismatch or unrecognised value.
// Before — falsy values bypass the guard entirely
if (parsed.location && !LOCATION_IDS.has(parsed.location)) {
    delete parsed.location;
}

// After — any non-string or unrecognised value is rejected
if (parsed.location !== undefined) {
    if (typeof parsed.location !== 'string' || !LOCATION_IDS.has(parsed.location)) {
        delete parsed.location;
    }
}

Same pattern applied to parsed.weather. Consistent with how boolean flags are already validated in the same function.


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] [WIP] Address feedback on type validation for JSON from localStorage fix(persistence): strict type validation for location/weather from localStorage Mar 24, 2026
Copilot AI requested a review from rdtect March 24, 2026 10:17
Base automatically changed from security-fix-load-persisted-state-validation-13195613228722407853 to main March 24, 2026 11:07
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