Skip to content

Guard domain parsing to resolve TS2532 on malformed email inputs#11

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/fix-ts2532-undefined-error
Draft

Guard domain parsing to resolve TS2532 on malformed email inputs#11
Copilot wants to merge 6 commits intomainfrom
copilot/fix-ts2532-undefined-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

TypeScript consumers were hitting TS2532 because email.split('@')[1] can be undefined, yet toLowerCase() was called unconditionally. This PR makes domain extraction null-safe and keeps malformed inputs on the existing false path.

  • Domain extraction hardening

    • Updated detector logic to read the domain segment into an intermediate variable.
    • Added an early return when no domain segment is present.
    • Preserved behavior for valid emails by lowercasing only after the guard.
  • Focused regression coverage

    • Expanded test/package.ts assertions to cover:
      • a known disposable domain (true)
      • standard non-disposable email (false)
      • malformed inputs (invalid-email, @, user@@example.com, empty string) returning false
const domainPart = email.split('@')[1];
if (!domainPart) return false;
const domain = domainPart.toLowerCase();
return disposableDomains.includes(domain);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pastebin.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node test/usage.js (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node test/usage.js detector osable-email-detector (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@deepsource-io
Copy link
Copy Markdown
Contributor

deepsource-io Bot commented Apr 15, 2026

DeepSource Code Review

We reviewed changes in da406b2...929330b on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Apr 15, 2026 5:15p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 15, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 36 complexity · 0 duplication

Metric Results
Complexity 36
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copilot AI changed the title [WIP] Fix TS2532: Resolve 'Object is possibly undefined' error Guard domain parsing to resolve TS2532 on malformed email inputs Apr 15, 2026
Copilot AI requested a review from IntegerAlex April 15, 2026 17:17
Copy link
Copy Markdown
Owner

@IntegerAlex IntegerAlex left a comment

Choose a reason for hiding this comment

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

LGTM

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.

[BUG] throws TS2532: Object is possibly 'undefined' at index.ts:58

2 participants