Skip to content

fix: require a hostname in url() - #259

Closed
dajiaohuang wants to merge 1 commit into
af:mainfrom
dajiaohuang:fix/url-requires-hostname
Closed

dajiaohuang wants to merge 1 commit into
af:mainfrom
dajiaohuang:fix/url-requires-hostname

Conversation

@dajiaohuang

Copy link
Copy Markdown

What changed

The README describes url() as requiring a protocol and hostname, but new URL() also accepts valid non-host URL forms such as mailto:. The validator now rejects parsed URLs without a hostname while continuing to accept host-bearing custom schemes. Error messages remain generic and do not include the input value.

Tests and validation

  • Added a synthetic mailto: case; it failed before the change because validation accepted it.
  • bun run test:ci -- tests/validators.test.ts — 9 passed
  • bun run ts — passed
  • bun run lint — passed
  • git diff --check — passed

No real process.env, .env, credentials, user profile, deployment configuration, or service was accessed. No full suite/build was run.

@af

af commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR! I don't really see this as a problem though– if it's a valid url, it's a valid url. If you want to create a stricter validation to ensure there's a hostname, a custom validator is probably the right place for that.

@af af closed this Oct 30, 2026
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