Normalize domains at read time in getStoredDomains#67
Conversation
…+ type guard) Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Normalizes exception domain entries when reading them from browser.storage.sync in the popup, improving robustness against manually-injected/externally-modified storage values (e.g., whitespace and mixed case) that could otherwise display incorrectly or break removal.
Changes:
- Normalize stored domain entries at read time by filtering to strings and applying
trim().toLowerCase()ingetStoredDomains.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return Array.isArray(stored[STORAGE_KEY]) ? stored[STORAGE_KEY] : []; | ||
| return Array.isArray(stored[STORAGE_KEY]) | ||
| ? stored[STORAGE_KEY] | ||
| .filter((domain) => typeof domain === "string") |
There was a problem hiding this comment.
getStoredDomains now trims/lowers strings but it can still return empty strings when a stored entry is whitespace-only (e.g. " "). That will render a blank list item and may lead to confusing remove behavior. Consider filtering out entries where domain.trim() is falsy (similar to background.js’s updateExceptionDomains).
| .filter((domain) => typeof domain === "string") | |
| .filter((domain) => typeof domain === "string" && domain.trim()) |
Domains injected directly into
browser.storage.sync(e.g. via devtools or an external process) could contain leading/trailing whitespace or mixed case, causing incorrect display in the popup and broken remove operations.Changes
popup.js—getStoredDomains: normalize every entry on retrieval with afilter+trim+toLowerCasechain before returning the array.The
typeofguard defensively drops non-string entries that would otherwise throw at.trim().Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.