diff --git a/engine/src/ast/field_expr.rs b/engine/src/ast/field_expr.rs index bbe9dc78..990e4d90 100644 --- a/engine/src/ast/field_expr.rs +++ b/engine/src/ast/field_expr.rs @@ -2646,9 +2646,9 @@ mod tests { // Matches operator let parser = FilterParser::new(&SCHEME); - let r = Regex::new("a.b", RegexFormat::Literal, &parser).unwrap(); + let r = Regex::new("a.b", RegexFormat::Literal, parser.settings()).unwrap(); let expr = assert_ok!( - FilterParser::new(&SCHEME).lex_as("http.host matches r###\"a.b\"###"), + parser.lex_as("http.host matches r###\"a.b\"###"), ComparisonExpr { lhs: IndexExpr { identifier: IdentifierExpr::Field(field("http.host")), diff --git a/engine/src/rhs_types/regex/imp_real.rs b/engine/src/rhs_types/regex/imp_real.rs index e3a35138..750b7fa1 100644 --- a/engine/src/rhs_types/regex/imp_real.rs +++ b/engine/src/rhs_types/regex/imp_real.rs @@ -1,4 +1,4 @@ -use crate::{FilterParser, RegexFormat}; +use crate::{ParserSettings, RegexFormat}; pub use regex::Error; @@ -14,12 +14,12 @@ impl Regex { pub fn new( pattern: &str, format: RegexFormat, - parser: &FilterParser<'_>, + settings: &ParserSettings, ) -> Result { ::regex::bytes::RegexBuilder::new(pattern) .unicode(false) - .size_limit(parser.settings.regex_compiled_size_limit) - .dfa_size_limit(parser.settings.regex_dfa_size_limit) + .size_limit(settings.regex_compiled_size_limit) + .dfa_size_limit(settings.regex_dfa_size_limit) .build() .map(|r| Regex { compiled_regex: r, @@ -51,15 +51,13 @@ impl From for regex::bytes::Regex { #[test] fn test_compiled_size_limit() { - use crate::Scheme; - - let scheme = Scheme::default(); - const COMPILED_SIZE_LIMIT: usize = 1024 * 1024; - let mut parser = FilterParser::new(&scheme); - parser.regex_set_compiled_size_limit(COMPILED_SIZE_LIMIT); + let settings = ParserSettings { + regex_compiled_size_limit: COMPILED_SIZE_LIMIT, + ..Default::default() + }; assert_eq!( - Regex::new(".{4079,65535}", RegexFormat::Literal, &parser), + Regex::new(".{4079,65535}", RegexFormat::Literal, &settings), Err(Error::CompiledTooBig(COMPILED_SIZE_LIMIT)) ); } diff --git a/engine/src/rhs_types/regex/mod.rs b/engine/src/rhs_types/regex/mod.rs index 425cdde3..e5c84af6 100644 --- a/engine/src/rhs_types/regex/mod.rs +++ b/engine/src/rhs_types/regex/mod.rs @@ -52,7 +52,7 @@ fn lex_regex_from_raw_string<'i>( parser: &FilterParser<'_>, ) -> LexResult<'i, Regex> { let ((lexed, hashes), input) = lex_raw_string_as_str(input)?; - match Regex::new(lexed, RegexFormat::Raw(hashes), parser) { + match Regex::new(lexed, RegexFormat::Raw(hashes), parser.settings()) { Ok(regex) => Ok((regex, input)), Err(err) => Err((LexErrorKind::ParseRegex(err), input)), } @@ -94,7 +94,7 @@ fn lex_regex_from_literal<'i>(input: &'i str, parser: &FilterParser<'_>) -> LexR }; } }; - match Regex::new(®ex_buf, RegexFormat::Literal, parser) { + match Regex::new(®ex_buf, RegexFormat::Literal, parser.settings()) { Ok(regex) => Ok((regex, input)), Err(err) => Err((LexErrorKind::ParseRegex(err), regex_str)), } @@ -123,17 +123,19 @@ impl Serialize for Regex { #[cfg(test)] mod test { use super::*; - use crate::Scheme; + use crate::{ParserSettings, Scheme}; #[test] fn test() { let scheme = Scheme::new(); + let parser = FilterParser::new(&scheme); + let expr = assert_ok!( - Regex::lex_with(r#""[a-z"\]]+\d{1,10}\"";"#, &FilterParser::new(&scheme)), + Regex::lex_with(r#""[a-z"\]]+\d{1,10}\"";"#, &parser), Regex::new( r#"[a-z"\]]+\d{1,10}""#, RegexFormat::Literal, - &FilterParser::new(&scheme) + &ParserSettings::default(), ) .unwrap(), ";" @@ -142,7 +144,7 @@ mod test { assert_json!(expr, r#"[a-z"\]]+\d{1,10}""#); assert_err!( - Regex::lex_with(r#""abcd\"#, &FilterParser::new(&scheme)), + Regex::lex_with(r#""abcd\"#, &parser), LexErrorKind::MissingEndingQuote, "abcd\\" ); @@ -151,6 +153,8 @@ mod test { #[test] fn test_raw_string() { let scheme = Scheme::new(); + let parser = FilterParser::new(&scheme); + let expr = assert_ok!( Regex::lex_with( r###"r#"[a-z"\]]+\d{1,10}""#;"###, @@ -159,7 +163,7 @@ mod test { Regex::new( r#"[a-z"\]]+\d{1,10}""#, RegexFormat::Raw(1), - &FilterParser::new(&scheme) + parser.settings(), ) .unwrap(), ";" @@ -170,12 +174,12 @@ mod test { let expr = assert_ok!( Regex::lex_with( r##"r#"(?u)\*\a\f\t\n\r\v\x7F\x{10FFFF}\u007F\u{7F}\U0000007F\U{7F}"#"##, - &FilterParser::new(&scheme) + &parser, ), Regex::new( r#"(?u)\*\a\f\t\n\r\v\x7F\x{10FFFF}\u007F\u{7F}\U0000007F\U{7F}"#, RegexFormat::Raw(1), - &FilterParser::new(&scheme) + parser.settings(), ) .unwrap(), ""