Skip to content

Normalize domains at read time in getStoredDomains#67

Merged
ormidales merged 2 commits into1.0.3from
copilot/fix-accidental-space-storage
Feb 28, 2026
Merged

Normalize domains at read time in getStoredDomains#67
ormidales merged 2 commits into1.0.3from
copilot/fix-accidental-space-storage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 28, 2026

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.jsgetStoredDomains: normalize every entry on retrieval with a filter + trim + toLowerCase chain before returning the array.
// Before
return Array.isArray(stored[STORAGE_KEY]) ? stored[STORAGE_KEY] : [];

// After
return Array.isArray(stored[STORAGE_KEY])
  ? stored[STORAGE_KEY]
      .filter((domain) => typeof domain === "string")
      .map((domain) => domain.trim().toLowerCase())
  : [];

The typeof guard defensively drops non-string entries that would otherwise throw at .trim().

Original prompt

This section details on the original issue you should resolve

<issue_title>Tolérance aux espaces accidentels dans le stockage des exceptions</issue_title>
<issue_description>## Contexte
L'extension synchronise les domaines en liste blanche via browser.storage.sync. Le background script lit ces domaines pour peupler un Set utilisé pour valider les requêtes.

Problème

Bien que l'ajout via le popup gère correctement la normalisation (en minuscules), si un utilisateur ou un autre processus modifie manuellement le stockage synchronisé en y injectant des espaces (ex: " example.com "), le popup affichera ces espaces de manière erronée et la comparaison dans background.js pourrait échouer malgré le .trim() présent dans updateExceptionDomains, en cas de comparaison directe depuis le stockage sans rechargement.

Scénario de Reproduction

  1. Simuler l'ajout d'un domaine mal formaté dans browser.storage.sync via la console (ex: browser.storage.sync.set({ exceptionDomains: [" test.com "] })).
  2. Ouvrir le popup. Le domaine s'affiche avec des espaces.
  3. L'appui sur le bouton de suppression de ce domaine spécifique pourrait mal lier la chaîne s'il n'est pas proprement assaini.

Comportement Attendu

Les données issues de l'espace de stockage externe doivent être systématiquement normalisées (minuscules et sans espaces superflus) dès leur récupération par la fonction getStoredDomains du popup.

Pistes Techniques

  • Fichier concerné : popup.js.
  • Dans la fonction getStoredDomains, ajouter un .map(domain => domain.trim().toLowerCase()) avant de retourner le tableau des domaines.

Environnement

Toutes les plateformes.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…+ type guard)

Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix accidental space tolerance in exception storage Normalize domains at read time in getStoredDomains Feb 28, 2026
@ormidales ormidales added this to the v1.0.3 milestone Feb 28, 2026
@ormidales ormidales linked an issue Feb 28, 2026 that may be closed by this pull request
@ormidales ormidales marked this pull request as ready for review February 28, 2026 21:18
Copilot AI review requested due to automatic review settings February 28, 2026 21:18
@ormidales ormidales merged commit 5d4cfb9 into 1.0.3 Feb 28, 2026
@ormidales ormidales deleted the copilot/fix-accidental-space-storage branch February 28, 2026 21:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in getStoredDomains.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread popup.js
return Array.isArray(stored[STORAGE_KEY]) ? stored[STORAGE_KEY] : [];
return Array.isArray(stored[STORAGE_KEY])
? stored[STORAGE_KEY]
.filter((domain) => typeof domain === "string")
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
.filter((domain) => typeof domain === "string")
.filter((domain) => typeof domain === "string" && domain.trim())

Copilot uses AI. Check for mistakes.
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.

Tolérance aux espaces accidentels dans le stockage des exceptions

3 participants