Skip to content

Commit 163ac15

Browse files
committed
globset: escape { and } in escape
This appears to be an oversight from when `escape` was implemented in #2061.
1 parent e2362d4 commit 163ac15

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/globset/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,13 +928,26 @@ impl RequiredExtensionStrategyBuilder {
928928
///
929929
/// The escaping works by surrounding meta-characters with brackets. For
930930
/// example, `*` becomes `[*]`.
931+
///
932+
/// # Example
933+
///
934+
/// ```
935+
/// use globset::escape;
936+
///
937+
/// assert_eq!(escape("foo*bar"), "foo[*]bar");
938+
/// assert_eq!(escape("foo?bar"), "foo[?]bar");
939+
/// assert_eq!(escape("foo[bar"), "foo[[]bar");
940+
/// assert_eq!(escape("foo]bar"), "foo[]]bar");
941+
/// assert_eq!(escape("foo{bar"), "foo[{]bar");
942+
/// assert_eq!(escape("foo}bar"), "foo[}]bar");
943+
/// ```
931944
pub fn escape(s: &str) -> String {
932945
let mut escaped = String::with_capacity(s.len());
933946
for c in s.chars() {
934947
match c {
935948
// note that ! does not need escaping because it is only special
936949
// inside brackets
937-
'?' | '*' | '[' | ']' => {
950+
'?' | '*' | '[' | ']' | '{' | '}' => {
938951
escaped.push('[');
939952
escaped.push(c);
940953
escaped.push(']');

0 commit comments

Comments
 (0)