1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Bounded regex compilation (Rules Rust — ReDoS / size_limit).
use ;
/// Max compiled regex heap for product patterns (NFA/bytecode budget).
///
/// Product patterns are fixed or escape-bounded (`regex::escape` + crate-name
/// charset). 256 KiB is far above those patterns and far below default 10 MiB
/// so a future dynamic pattern cannot balloon compile cost unnoticed.
pub const REGEX_SIZE_LIMIT_BYTES: usize = 256 * 1024;
/// Max DFA cache for product patterns (mirror of [`REGEX_SIZE_LIMIT_BYTES`]).
pub const REGEX_DFA_SIZE_LIMIT_BYTES: usize = 256 * 1024;
/// Compile a regex with explicit `size_limit` / `dfa_size_limit` (ReDoS posture).
///
/// Prefer this over bare [`Regex::new`] everywhere in product code.
///
/// # Errors
///
/// Returns the underlying [`regex::Error`] when the pattern is invalid or
/// exceeds the size budgets.
pub
/// True when `c` is a C0/C1 control **or** a format/invisible character that
/// must not appear in free-text CLI input (bidi overrides, zero-width, BOM).
///
/// Domain identifiers (crate name, item path, version) already restrict to
/// ASCII alphanumerics; this gate is for [`super::SearchQuery`] free text.
pub