Skip to content

Commit 8b91374

Browse files
committed
feat: add method to check if no_proxy is empty
Signed-off-by: Jérémie Drouet <[email protected]>
1 parent 06f0fa3 commit 8b91374

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ pub struct NoProxy {
9191
impl NoProxy {
9292
fn from_iterator<V: AsRef<str>, I: Iterator<Item = V>>(iterator: I) -> Self {
9393
let content: HashSet<_> = iterator
94-
.map(|item| NoProxyItem::from(item.as_ref().trim().to_string()))
94+
.map(|item| item.as_ref().trim().to_string())
95+
.filter(|item| !item.is_empty())
96+
.map(NoProxyItem::from)
9597
.collect();
9698
let has_wildcard = content.contains(&NoProxyItem::Wildcard);
9799
Self {
@@ -136,6 +138,10 @@ impl Extend<NoProxyItem> for NoProxy {
136138
}
137139

138140
impl NoProxy {
141+
pub fn is_empty(&self) -> bool {
142+
self.content.is_empty()
143+
}
144+
139145
pub fn matches(&self, input: &str) -> bool {
140146
if self.has_wildcard {
141147
return true;
@@ -183,6 +189,12 @@ mod tests {
183189
);
184190
}
185191

192+
#[test]
193+
fn filter_empty() {
194+
let no_proxy = NoProxy::from("");
195+
assert!(no_proxy.is_empty());
196+
}
197+
186198
#[test]
187199
fn wildcard() {
188200
should_match("*", "www.wikipedia.org");

src/serialize.rs

+2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ mod tests {
6565
// parsing a comma separated string
6666
let result: NoProxy = serde_json::from_str(&json).unwrap();
6767
assert_eq!(proxy, result);
68+
assert_eq!(result.content.len(), 2);
6869
// parsing an array of strings
6970
let result: NoProxy = serde_json::from_str(r#"["foo.bar", "1.2.3.4"]"#).unwrap();
7071
assert_eq!(proxy, result);
72+
assert_eq!(result.content.len(), 2);
7173
}
7274
}

0 commit comments

Comments
 (0)