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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Shell-oriented helpers for the `MiniJinja` standard library.
//!
//! The helpers bridge template values into the local shell while keeping
//! behaviour predictable across platforms. All helpers mark the stdlib state as
//! impure so the caller can invalidate any caching layer that depends on pure
//! template evaluation.
//!
//! # Output limits
//!
//! Capture and streaming helpers enforce configurable byte budgets to prevent
//! helpers from exhausting memory or disk space. Callers configure distinct
//! ceilings for `stdout` capture and streamed tempfile output through
//! `StdlibConfig`, and the runtime raises descriptive errors when a command
//! exceeds either limit.
//!
//! # Windows quoting strategy
//!
//! Windows does not ship a widely-used Rust crate that can reliably escape
//! `cmd.exe` arguments. General Windows bindings such as `winsafe` expose
//! Win32 APIs but leave command-line quoting to the caller, and no alternative
//! crate currently offers a robust drop-in solution. We therefore maintain a
//! small implementation derived from the official [`CommandLineToArgvW`][ms-argv]
//! documentation and the detailed guidance on [metacharacter handling][ss64]. The
//! routine emits double-quoted arguments when required and escapes
//! metacharacters (`^`, `&`, `|`, `<`, `>`, `%`, and `!`) so that `cmd.exe`
//! always treats templated data as literals. Double quotes within the argument
//! are escaped with a caret so the shell preserves them, while preceding
//! backslashes are passed through unchanged because `cmd.exe` does not treat `\`
//! as an escape character. Line-feed and carriage-return characters are rejected
//! outright because `cmd.exe` interprets them as command terminators even inside
//! quotes. When the command reaches the invoked program the Windows argument
//! splitter applies the [`CommandLineToArgvW`][ms-argv] backslash rules, so
//! sequences such as `\"` still deliver the intended backslashes alongside the
//! literal quote.
//!
//! [ms-argv]: https://learn.microsoft.com/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw
//! [ss64]: https://ss64.com/nt/syntax-esc.html
//!
//! # Security
//!
//! The `shell` and `grep` filters execute external commands based on template
//! content. Templates using these filters must come from trusted sources only.
//! Never allow untrusted input to control command strings or patterns, as this
//! enables arbitrary code execution.
pub use value_from_bytes;
pub use ;
use ;
use CommandOptions;
use ;
use ;
use ;
/// Registers shell-oriented filters in the `MiniJinja` environment.
///
/// The `shell` filter executes arbitrary shell commands and returns their
/// stdout. The `grep` filter searches input text using the `grep` utility.
/// Both filters mark the provided `impure` flag to signal that template
/// evaluation has side effects and should not be cached.
///
/// # Security
///
/// Only use these filters with trusted templates. See the module-level
/// documentation for further details about the associated risks.
pub