Skip to content

Commit

Permalink
perf: Faster uri-reference validation
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
Stranger6667 committed Sep 28, 2024
1 parent 886debb commit 25811ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ While backward compatibility is maintained for now, users are encouraged to upda
- Changing base URI in folder.
- Location-independent identifier in remote resource.

### Performance

- Faster `uri-reference` validation.

## [0.20.0] - 2024-09-18

**Important:** This release includes several deprecations and renames. While backward compatibility is maintained for now, users are encouraged to update their code. See the [Migration Guide](MIGRATION.md) for details on transitioning to the new API.
Expand Down
5 changes: 5 additions & 0 deletions crates/jsonschema-py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- `$anchor` support.
- `$recursiveRef` & `$recursiveAnchor` support in Draft 2019-09.

### Changed

Expand All @@ -19,6 +20,10 @@
- Changing base URI in folder.
- Location-independent identifier in remote resource.

### Performance

- Faster `uri-reference` validation.

## [0.20.0] - 2024-09-18

### Added
Expand Down
6 changes: 1 addition & 5 deletions crates/jsonschema/src/keywords/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ static TIME_RE: Lazy<Regex> = Lazy::new(|| {
r"^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\.[0-9]{6})?(([Zz])|([+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))\z",
).expect("Is a valid regex")
});
static URI_REFERENCE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^(\w+:(/?/?))?[^#\\\s]*(#[^\\\s]*)?\z").expect("Is a valid regex"));
static URI_TEMPLATE_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*})*\z"#
Expand Down Expand Up @@ -310,9 +308,7 @@ impl Validate for URIReferenceValidator {
validate!("uri-reference");
fn is_valid(&self, instance: &Value) -> bool {
if let Value::String(item) = instance {
URI_REFERENCE_RE
.is_match(item)
.expect("Simple URI_REFERENCE_RE pattern")
referencing::UriRef::parse(item.as_str()).is_ok()
} else {
true
}
Expand Down

0 comments on commit 25811ce

Please sign in to comment.