leadpony / justify

Justify is a JSON validator based on JSON Schema Specification and Jakarta JSON Processing API (JSON-P).
Apache License 2.0
96 stars 18 forks source link

URI format validation not working #42

Closed goncalonsp closed 4 years ago

goncalonsp commented 4 years ago

I've encountered an issue while validating uri formatted properties. As it seems, no validation is done whatsoever. Is this an expected behavior?

Check the following repo reproducing the error (simply run the App.java class): https://github.com/goncalonsp/justify-uri-validation-issue

In summary the schema is:

{
  "$id": "salesforce.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Example object",
  "description": "My example object",
  "type": "object",
  "required": [
    "url"
  ],
  "properties": {
    "url": {
      "type": "string",
      "title": "My example URL",
      "format": "uri"
    }
  }
}

and the object being validated:

{
  "url": "http:/john.acme.com"
}

Where http:/john.acme.com is invalid and should be http://jonh.acme.com instead.

leadpony commented 4 years ago

@goncalonsp Thank you for using this small library. I believe http:/john.acme.com is a valid absolute URI. If checking with java.net.URI:

URI url = URI.create("http:/john.acme.com");
System.out.println(url.isAbsolute());

The RFC 3986 states:

URI  = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

hier-part   = "//" authority path-abempty
    / path-absolute
    / path-rootless
    / path-empty

Here path-absolute starts with a single /.

path-absolute = "/" [ segment-nz *( "/" segment ) ]
leadpony commented 4 years ago

Justify checks whether the given string is a valid URI or not based on the RFC 3986. It does not check any scheme-specific constraints, such as the constraints of http URL. This behavior is the same as java.net.URI class.

goncalonsp commented 4 years ago

Thank you for your swift response! I will close this issue.