Skip to content

"ipv4" format validator rejects 0.x.y.z IPs #512

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

Closed
GREsau opened this issue Sep 14, 2024 · 2 comments · Fixed by #513
Closed

"ipv4" format validator rejects 0.x.y.z IPs #512

GREsau opened this issue Sep 14, 2024 · 2 comments · Fixed by #513

Comments

@GREsau
Copy link
Contributor

GREsau commented Sep 14, 2024

let schema = jsonschema::compile(&json!({
    "type": "string",
    "format": "ipv4"
})).unwrap();

println!("{}", schema.is_valid(&json!("0.0.0.0")));

This outputs false, when I would expect true because 0.0.0.0 is a valid dotted-quad representation of an IPv4 address. All other IP addresses starting with 0 (e.g. 0.1.2.3) are similarly rejected.

This appears to be due to the fix for json-schema-org/JSON-Schema-Test-Suite#469 (commit 7d32eff), but I think this particular fix is simultaneously:

  • too strict, e.g. it rejects 0.0.0.0
  • too loose because it allows leading zeroes in the second/third/fourth octets, e.g. it allows 1.0123.1.1
  • unnecessary, because Ipv4Addr's FromStr implementation already disallows leading zeros in any octet. Edit: this was only added in rust 1.58 (Reject octal zeros in IPv4 addresses rust-lang/rust#86984), so the explicit check in this crate wasn't unnecessary when it was first implemented!
@Stranger6667
Copy link
Owner

Thank you! Indeed, you are right! I’ll fix it soon

@Stranger6667
Copy link
Owner

Fixed in 0.19.1

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 a pull request may close this issue.

2 participants