-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hostname format validation problem #208
Comments
So the JSON schema spec references RFC 1034 which does not allow for (sub)domains to start with a digit. In practice however there numerous domains that start with a digit and RFC 1123 actually allows starting digits in (sub)domains, but that leads to the problem that IP addresses are suddenly also valid domain names. The regex currently used allows for (sub)domains to start with a digit and is therefore indeed strictly speaking not RFC 1034 compliant. I'm not sure how to tackle this problem. It's a bit embarrassing that an example from the json-schema.org site doesn't work as expected, but I think breaking the validation of domain names that use RFC 1123 is also less than ideal as they're quite common. Another workaround is to explicitly check for an ipv4 address and fail the hostname format validation if it's also an ipv4 address. @handrews I could really use your opinion on this one. |
@johandorland yeah, JSON Schema can't really fix ambiguities and imperfect real-world conformance with regards to other RFCs. This is part of why @soslanco I would use {
"format": "hostname",
"not": {"format": "ipv4"}
} which I suppose you could also use in a @soslanco if you want to file an issue on that example at https://github.com/json-schema-org/json-schema-org.github.io/issues that would be great. |
anyOf work fine, but json schema specification say:
imho behavior of hostname format must be as specified. |
for example if specification say:
then how must foobar work? |
@soslanco neither the JSON Schema specification nor JSON Schema implementations can fix ambiguous and conflicting specifications. The problem here is that the internet does not entirely follow RFC 1034, so implementations need to decide what the right trade-off is. See also the section on implementation requirements for |
Why IPv4 address is hostname, but IPv6 not? |
It's a coincidence of syntax. IPv4 and hostnames are both dot-separated, but IPv6 is colon separated. None of this is specific to JSON Schema at all. |
|
One of solution is adding strict mode for full compatibility with specification. |
As one of the two primary editors of the JSON Schema specification, I am going to state this unambiguously: This Go implementation is in conformance with the JSON Schema specification as long as it allows every valid hostname. It is expected that formats with ambiguous, difficult, or conflicting rules will not necessarily catch every semantically invalid value. The implementation should document all known limitations with each supported format, but when it comes to And with that I will leave the rest of this issue's resolution to @johandorland . If we need to improve the examples on the web site, please file an issue there. |
After sleeping a night on it I'm going to mark this as won't fix. RFC 1034 is outdated and does not reflect real world use. Clearly I'm not alone on this as with one exception every other JSON schema implementation I checked also does not follow RFC 1034 strictly and also allows ipv4 addresses as hostnames. I'm also not a big fan of a strict mode, @handrews hit the nail on the head quite well on that issue. |
The best one solution is changing specification :-) |
@soslanco I invite you to go to the IETF and have fun trying to change RFC 1034. Please stop asking us to change things that are not under our control. |
Thanks, but i am talking about JSON Schema specification.
P.S. One of (specification or software) are wrong. |
But this validator (gojsonschema) the best one what i used! ;-) |
Regular expression in hostname format doesn't comply specification from json-schema.org.
Following example from json-schema.org doesn't work because ipv4 addresses detect as valid hostnames too.
The text was updated successfully, but these errors were encountered: