fix: Panic in `JSONSchema.apply` on some schemas with `prefixItems` and `items`

This commit is contained in:
Dmitry Dygalo 2021-12-08 11:58:29 +01:00 committed by Dmitry Dygalo
parent 295246619a
commit bd76d74212
2 changed files with 3 additions and 2 deletions

View File

@ -8,8 +8,9 @@
### Fixed
- False positives in some cases when calling `JSONSchema.apply` on a schema with `additionalProperties`, `patternProperties`, and `properties` combined.
- False positives in some cases when calling `JSONSchema.apply` on schemas with `additionalProperties`, `patternProperties`, and `properties` combined.
- False negatives in some cases when calling `JSONSchema.apply` on schemas with `if` and `then` (without `else`) keywords. [#318](https://github.com/Stranger6667/jsonschema-rs/pull/318)
- Panic in `JSONSchema.apply` on some schemas with `prefixItems` and `items`. It panicked if `items` is an object and the length of `prefixItems` is greater than the length of the input array.
### Performance

View File

@ -204,7 +204,7 @@ impl Validate for ItemsObjectSkipPrefixValidator {
instance_path: &InstancePath,
) -> PartialApplication<'a> {
if let Value::Array(items) = instance {
let mut results = Vec::with_capacity(items.len() - self.skip_prefix);
let mut results = Vec::with_capacity(items.len().saturating_sub(self.skip_prefix));
for (idx, item) in items.iter().skip(self.skip_prefix).enumerate() {
let path = instance_path.push(idx + self.skip_prefix);
results.push(self.node.apply_rooted(item, &path));