fix: The `format` validator incorrectly rejecting supported regex patterns
Ref: #230
This commit is contained in:
parent
550ed821b6
commit
e24630567f
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- The `format` validator incorrectly rejecting supported regex patterns. [#230](https://github.com/Stranger6667/jsonschema-rs/issues/230)
|
||||
|
||||
## [0.9.0] - 2021-05-07
|
||||
|
||||
### Added
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- The `format` validator incorrectly rejecting supported regex patterns. [#230](https://github.com/Stranger6667/jsonschema-rs/issues/230)
|
||||
|
||||
## [0.9.0] - 2021-05-07
|
||||
|
||||
### Added
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use crate::{
|
||||
compilation::{context::CompilationContext, JSONSchema},
|
||||
error::{error, no_error, CompilationError, ErrorIterator, ValidationError},
|
||||
keywords::CompilationResult,
|
||||
keywords::{pattern, CompilationResult},
|
||||
paths::InstancePath,
|
||||
validator::Validate,
|
||||
Draft,
|
||||
|
@ -267,7 +267,7 @@ impl Validate for RegexValidator {
|
|||
validate!("regex");
|
||||
fn is_valid(&self, _: &JSONSchema, instance: &Value) -> bool {
|
||||
if let Value::String(item) = instance {
|
||||
Regex::new(item).is_ok()
|
||||
pattern::convert_regex(item).is_ok()
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
@ -381,4 +381,13 @@ mod tests {
|
|||
let compiled = JSONSchema::compile(&schema).unwrap();
|
||||
assert!(compiled.is_valid(&instance))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ecma_regex() {
|
||||
// See GH-230
|
||||
let schema = json!({"format": "regex", "type": "string"});
|
||||
let instance = json!("^\\cc$");
|
||||
let compiled = JSONSchema::compile(&schema).unwrap();
|
||||
assert!(compiled.is_valid(&instance))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ impl ToString for PatternValidator {
|
|||
}
|
||||
|
||||
// ECMA 262 has differences
|
||||
fn convert_regex(pattern: &str) -> Result<fancy_regex::Regex, fancy_regex::Error> {
|
||||
pub(crate) fn convert_regex(pattern: &str) -> Result<fancy_regex::Regex, fancy_regex::Error> {
|
||||
// replace control chars
|
||||
let new_pattern = CONTROL_GROUPS_RE.replace_all(pattern, replace_control_group);
|
||||
let mut out = String::with_capacity(new_pattern.len());
|
||||
|
|
Loading…
Reference in New Issue