From 234cbaf06581257bce5a1ea7354e2732e66ddd21 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Wed, 13 Nov 2024 10:25:55 +1100 Subject: [PATCH] chore(pact-models): Upgraded rand_regex to 0.17.0 --- rust/Cargo.lock | 16 +++++++++++++--- rust/pact_models/Cargo.toml | 4 ++-- rust/pact_models/src/generators/mod.rs | 13 ++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 316e5be0..c1224ee4 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2207,7 +2207,7 @@ dependencies = [ "pretty_assertions", "quickcheck", "rand", - "rand_regex", + "rand_regex 0.15.1", "regex", "regex-syntax 0.6.29", "reqwest", @@ -2369,9 +2369,9 @@ dependencies = [ "parse-zoneinfo", "pretty_assertions", "rand", - "rand_regex", + "rand_regex 0.17.0", "regex", - "regex-syntax 0.6.29", + "regex-syntax 0.8.5", "reqwest", "rstest 0.23.0", "semver", @@ -2861,6 +2861,16 @@ dependencies = [ "regex-syntax 0.6.29", ] +[[package]] +name = "rand_regex" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bfbd599a8c757f89100e3ae559fb1ef9efa1cfd9276136862e3089dec627b31" +dependencies = [ + "rand", + "regex-syntax 0.8.5", +] + [[package]] name = "rayon" version = "1.10.0" diff --git a/rust/pact_models/Cargo.toml b/rust/pact_models/Cargo.toml index 576afdce..0bc726e8 100644 --- a/rust/pact_models/Cargo.toml +++ b/rust/pact_models/Cargo.toml @@ -38,9 +38,9 @@ maplit = "1.0.2" mime = "0.3.17" nom = "7.1.3" rand = "0.8.5" -rand_regex = "0.15.1" +rand_regex = "0.17.0" regex = "1.8.4" -regex-syntax = "0.6.27" +regex-syntax = "0.8.5" semver = "1.0.17" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" diff --git a/rust/pact_models/src/generators/mod.rs b/rust/pact_models/src/generators/mod.rs index bd68b191..21bfb0a1 100644 --- a/rust/pact_models/src/generators/mod.rs +++ b/rust/pact_models/src/generators/mod.rs @@ -1069,10 +1069,10 @@ impl GenerateValue for Generator { Generator::RandomString(size) => Ok(json!(generate_ascii_string(*size as usize))), Generator::Regex(ref regex) => { let mut parser = regex_syntax::ParserBuilder::new().unicode(false).build(); - match parser.parse(regex) { + match parser.parse(strip_anchors(regex)) { Ok(hir) => { match rand_regex::Regex::with_hir(hir, 20) { - Ok(gen) => Ok(json!(rand::thread_rng().sample::(gen))), + Ok(gen) => Ok(json!(thread_rng().sample::(gen))), Err(err) => { warn!("Failed to generate a value from regular expression - {}", err); Err(anyhow!("Failed to generate a value from regular expression - {}", err)) @@ -1362,7 +1362,6 @@ mod tests { use pretty_assertions::assert_eq; use test_log::test; - use crate::contain; use crate::generators::Generator::{RandomDecimal, RandomInt, Regex}; use super::*; @@ -2103,14 +2102,10 @@ mod tests { let generator = Generator::Regex(r"^\/api\/families\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$".into()); let generated = generator.generate_value(&"".to_string(), &hashmap!{}, &NoopVariantMatcher.boxed()); - let err = generated.unwrap_err().to_string(); - expect!(&err).to(contain("'^\\/api\\/families\\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$' is not a valid regular expression")); - expect!(&err).to(contain("error: unrecognized escape sequence")); + assert_that!(generated.unwrap(), matches_regex(r"\/api\/families\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}")); let generated = generator.generate_value(&json!(""), &hashmap!{}, &NoopVariantMatcher.boxed()); - let err = generated.unwrap_err().to_string(); - expect!(&err).to(contain("'^\\/api\\/families\\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$' is not a valid regular expression")); - expect!(&err).to(contain("error: unrecognized escape sequence")); + assert_that!(generated.unwrap().as_str().unwrap(), matches_regex(r"\/api\/families\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}")); } #[test]