Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions engine/src/ast/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ impl Display for ParseError<'_> {
/// Parser settings.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParserSettings {
/// Approximate size of the cache used by the DFA of a regex.
/// Default: 10MB
pub regex_dfa_size_limit: usize,
/// Approximate size limit of the compiled regular expression.
/// Default: 2MB
/// Default: 10MB
pub regex_compiled_size_limit: usize,
/// Approximate size of the cache used by the DFA of a regex.
/// Default: 2MB
pub regex_dfa_size_limit: usize,
/// Capacity of the managed Cache pool.
/// Default: 8
pub regex_pool_capacity: usize,
/// Maximum number of star metacharacters allowed in a wildcard.
/// Default: unlimited
pub wildcard_star_limit: usize,
Expand All @@ -119,6 +122,8 @@ impl Default for ParserSettings {
regex_compiled_size_limit: 10 * (1 << 20),
// Default value extracted from the regex crate.
regex_dfa_size_limit: 2 * (1 << 20),
// Default value extracted from the regex crate.
regex_pool_capacity: 8,
wildcard_star_limit: usize::MAX,
max_nesting_depth: 128,
}
Expand Down Expand Up @@ -227,6 +232,18 @@ impl<'s> FilterParser<'s> {
self.settings.regex_dfa_size_limit
}

/// Set capacity of the managed Cache pool.
#[inline]
pub fn regex_set_pool_capacity(&mut self, pool_capacity: usize) {
self.settings.regex_pool_capacity = pool_capacity;
}

/// Get capacity of the managed Cache pool.
#[inline]
pub fn regex_get_pool_capacity(&self) -> usize {
self.settings.regex_pool_capacity
}

/// Set the maximum number of star metacharacters allowed in a wildcard.
#[inline]
pub fn wildcard_set_star_limit(&mut self, wildcard_star_limit: usize) {
Expand Down
8 changes: 4 additions & 4 deletions engine/src/rhs_types/regex/imp_real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ pub struct Regex {
impl Regex {
/// Retrieves the syntax configuration that will be used to build the regex.
#[inline]
fn syntax_config() -> regex_automata::util::syntax::Config {
pub fn syntax_config() -> regex_automata::util::syntax::Config {
regex_automata::util::syntax::Config::new()
.unicode(false)
.utf8(false)
}

/// Retrieves the meta configuration that will be used to build the regex.
#[inline]
fn meta_config(settings: &ParserSettings) -> regex_automata::meta::Config {
pub fn meta_config(settings: &ParserSettings) -> regex_automata::meta::Config {
regex_automata::meta::Config::new()
.match_kind(MatchKind::LeftmostFirst)
.utf8_empty(false)
.dfa(false)
.nfa_size_limit(Some(settings.regex_compiled_size_limit))
.onepass(false)
.dfa_size_limit(Some(settings.regex_compiled_size_limit))
.nfa_size_limit(Some(settings.regex_compiled_size_limit))
.hybrid_cache_capacity(settings.regex_dfa_size_limit)
.pool_capacity(settings.regex_pool_capacity)
.which_captures(WhichCaptures::None)
}

Expand Down
Loading