Skip to content

Commit bf9c618

Browse files
committed
CHANGELOG + fix escaped pattern'
1 parent db04c26 commit bf9c618

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
## Added
11+
12+
- wildcard_iter that supports \* (any) and ? (one) wildcards in search pattern
13+
814
## [1.1.1]
915

1016
## Fixed

src/node_common.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ impl WildcardFilter {
11951195
}
11961196
}
11971197
}
1198+
escaped = false;
11981199
}
11991200
patterns
12001201
}
@@ -2821,4 +2822,49 @@ mod tests {
28212822
.collect();
28222823
assert_eq!(matches, vec!["foobar"]);
28232824
}
2825+
2826+
#[test]
2827+
fn wildcard_parse_escaped() {
2828+
assert_eq!(WildcardFilter::parse(b"\\*"), vec![Pattern::Literal(b"*")]);
2829+
2830+
assert_eq!(WildcardFilter::parse(b"\\?"), vec![Pattern::Literal(b"?")]);
2831+
2832+
// escaped wildcard followed by literal chars
2833+
assert_eq!(
2834+
WildcardFilter::parse(b"\\*foo"),
2835+
vec![Pattern::Literal(b"*foo")]
2836+
);
2837+
2838+
// mix: literal prefix, escaped *, literal suffix
2839+
assert_eq!(
2840+
WildcardFilter::parse(b"foo.\\*.com"),
2841+
vec![Pattern::Literal(b"foo."), Pattern::Literal(b"*.com")]
2842+
);
2843+
}
2844+
2845+
#[test]
2846+
fn wildcard_iter_escaped() {
2847+
let mut set = RadixSet::new();
2848+
set.insert("foo.*.com");
2849+
set.insert("foo.bar.com");
2850+
set.insert("foo.?.com");
2851+
2852+
let matches: Vec<_> = set
2853+
.wildcard_iter(b"foo.\\*.com")
2854+
.map(|k| String::from_utf8(k).unwrap())
2855+
.collect();
2856+
assert_eq!(matches, vec!["foo.*.com"]);
2857+
2858+
let matches: Vec<_> = set
2859+
.wildcard_iter(b"foo.*.com")
2860+
.map(|k| String::from_utf8(k).unwrap())
2861+
.collect();
2862+
assert_eq!(matches.len(), 3);
2863+
2864+
let matches: Vec<_> = set
2865+
.wildcard_iter(b"foo.\\?.com")
2866+
.map(|k| String::from_utf8(k).unwrap())
2867+
.collect();
2868+
assert_eq!(matches, vec!["foo.?.com"]);
2869+
}
28242870
}

0 commit comments

Comments
 (0)