Comments (5)
I further spent some time checking the RFC specification (https://datatracker.ietf.org/doc/html/rfc3986#autoid-21), As per the specifications, a valid hostname could be
- ipv4 address
- ipv6 in square brackets
- A registered name, meeting criteria as per https://datatracker.ietf.org/doc/html/rfc1034#section-3.5
from zod.
Hi, first of all: I think this idea has potential in being implemented and used widely.
However this can be widely interpreted, hi.how.are.you.google.com is a valid domain, but should it be a valid hostname? Or should only google.com or example.com be valid.
Lets look at mozilla's definition on hostname:
https://hello.world.example.com/ -> url.hostname = hello.world.example.com
But should www
also be part of it?
from zod.
@m10rten Thanks for following up.
I believe the value returned from URL.hostname
should be considered a valid hostname. It may or may not include www
, depending on the domain, Ref: https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname
const url1 = new URL(
"https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname"
);
console.log(url1.hostname); // developer.mozilla.org
const url2 = new URL("https://hello.world.example.com/");
console.log(url2.hostname); // hello.world.example.com
const url3 = new URL("https://www.google.com/");
console.log(url3.hostname); // www.google.com
from zod.
Thanks for clearing that up!
Maybe we can work with that, how do you see using it? And what would the result look like?
Or exact like a new URL().hostname
?
from zod.
I think it should be used similarly to existing zod string validations, such as email or uuid.
So this will be z.string().hostname()
.
As for the implementation options:
- Adding a regex is one option.
- Another option is to check if a URL can be successfully constructed from the hostname string without throwing any errors. (I haven't tried this yet, so I'm not sure of the correctness of this option but can explore.)
from zod.
Related Issues (20)
- [Bug ?] Zod union ignoring zod object when fields are z.optional() HOT 3
- How to use discriminatedUnion with multiple conditions? HOT 1
- [Bug]: ZodFormattedError type breaks for ReadonlyArrays.
- safeParse not working server sider with z.union() : Error: Attempted to call indexOf() from the server but indexOf is on the client. HOT 1
- If object with nested refine fails, it doesn't apply transform before superRefine, causing superRefine to not be typesafe
- ZodReadonly missing methods to manipulate schema shape HOT 1
- Generic type function converting property with a default value to optional HOT 1
- Lowercase ULIDs should be considered valid ULIDs HOT 1
- Valid union-of-partials data does not parse even though it conforms to one (or more) of the union members HOT 1
- Changelog.md looks abandoned since version 3.10 HOT 1
- Zod .partial() no longer able to use programmatically HOT 1
- Overloaded function return schema with z.union
- Add support for `example` HOT 1
- Refine removes null from schema HOT 2
- Add `invalid_literal` ZodIssueCode to documentation
- Schema evolutions using zod?
- Support for curly braces around UUID/GUID
- ZodObject with generic key (i.e. [key: string]: xx) and specific key (i.e. {debug: xx}) don't _seem_ to work as expected
- zod parsing bug HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zod.