Skip to content
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

validate_schema does not report regex errors #194

Closed
Farjaad opened this issue Aug 20, 2024 · 1 comment
Closed

validate_schema does not report regex errors #194

Farjaad opened this issue Aug 20, 2024 · 1 comment

Comments

@Farjaad
Copy link

Farjaad commented Aug 20, 2024

The following raises a RegexpError instead of reporting that the regex is invalid

schema_definition = {
   "type" => "string",
    "pattern" => "/(/",
}
schema = JSONSchemer.schema(schema_definition)
errors = schema.validate_schema.to_a

Result: end pattern with unmatched parenthesis: /\/(\// (RegexpError)

@davishmcclurg
Copy link
Owner

Unfortunately, this is a known issue: #167 (comment)

JSONSchemer.schema still doesn't support invalid schemas (and likely won't). I don't want every schema object to have to take the hit of validating the provided schema before parsing. When working with schemas that are potentially invalid, it's best to check them with JSONSchemer.valid_schema? first.

Now that I think of it, JSONSchemer::Schema#valid_schema? and JSONSchemer::Schema#validate_schema were probably mistakes to begin with—may want to deprecate in the future.

Please use JSONSchemer.valid_schema? (or JSONSchemer.validate_schema) instead:

schema_definition = {
    "type" => "string",
    "pattern" => "/(/",
}

JSONSchemer.validate_schema(schema_definition).map { _1["error"] }
# ["value at `/pattern` does not match format: regex"]

davishmcclurg added a commit that referenced this issue Aug 24, 2024
These don't work very well because the schema is parsed before
validation occurs, which can raise errors.

See:
- #167 (comment)
- #194
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

No branches or pull requests

2 participants