Skip to content

fix(validation): accept localhost/IP in validateUrl and tighten email regex — #180#215

Merged
Jagadeeshftw merged 2 commits into
Grainlify:mainfrom
leocagli:fix/validation-180-url-email-edge-cases
Jun 23, 2026
Merged

fix(validation): accept localhost/IP in validateUrl and tighten email regex — #180#215
Jagadeeshftw merged 2 commits into
Grainlify:mainfrom
leocagli:fix/validation-180-url-email-edge-cases

Conversation

@leocagli

Copy link
Copy Markdown
Contributor

Summary

  • validateUrl: removed the hostname.includes('.') check that incorrectly rejected localhost, bare IPs, and other valid hosts. The URL constructor already enforces a non-empty hostname; javascript: and data: schemes are still blocked by the explicit protocol check.
  • validateEmail: upgraded regex from /[^\s@]+@[^\s@]+\.[^\s@]+/ to /[^\s@]+@[^\s@.]+(\.[^\s@.]+)+/ — rejects double dots in domain (user@example..com), missing domain before dot (user@.com), while supporting subdomains and avoiding catastrophic backtracking.
  • Tests: updated 1 existing test (localhost now accepted) and added 8 new edge-case tests.

Test plan

  • 41/41 tests pass (npx vitest run src/shared/utils/validation.test.ts)
  • https://localhost, http://localhost:3000, http://192.168.1.1 → accepted
  • javascript:alert(1), data:text/html,... → rejected
  • user@example..com, user@.com → rejected
  • user@mail.example.co.uk → accepted

Closes #180

🤖 Generated with Claude Code

leocagli and others added 2 commits June 23, 2026 13:33
… regex

validateUrl rejected localhost and bare IPs because of an overly strict
hostname.includes('.') check — legitimate dev/internal URLs were blocked.
Removed that check; the URL constructor already enforces a non-empty hostname.

validateEmail regex upgraded from /[^\s@]+@[^\s@]+\.[^\s@]+/ to
/[^\s@]+@[^\s@.]+(\.[^\s@.]+)+/ to reject double dots in domain (e.g.
user@example..com) and missing domain before the dot (user@.com) while
avoiding catastrophic backtracking.

Adds 8 new edge-case tests covering localhost, IPs, javascript:/data:
scheme rejection, double-dot domain, subdomain email, and missing domain.

Closes Grainlify#180

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jagadeeshftw Jagadeeshftw merged commit 6e161c8 into Grainlify:main Jun 23, 2026
@Jagadeeshftw

Copy link
Copy Markdown
Contributor

accepting localhost/IP in validateUrl while tightening the email regex covers the edge cases that always slip through. rebased on latest main, merged. thanks!

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.

Harden validateUrl/validateEmail in shared validation utils and add edge-case tests

3 participants