File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,9 @@ pub struct NoProxy {
91
91
impl NoProxy {
92
92
fn from_iterator < V : AsRef < str > , I : Iterator < Item = V > > ( iterator : I ) -> Self {
93
93
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)
95
97
. collect ( ) ;
96
98
let has_wildcard = content. contains ( & NoProxyItem :: Wildcard ) ;
97
99
Self {
@@ -136,6 +138,10 @@ impl Extend<NoProxyItem> for NoProxy {
136
138
}
137
139
138
140
impl NoProxy {
141
+ pub fn is_empty ( & self ) -> bool {
142
+ self . content . is_empty ( )
143
+ }
144
+
139
145
pub fn matches ( & self , input : & str ) -> bool {
140
146
if self . has_wildcard {
141
147
return true ;
@@ -183,6 +189,12 @@ mod tests {
183
189
) ;
184
190
}
185
191
192
+ #[ test]
193
+ fn filter_empty ( ) {
194
+ let no_proxy = NoProxy :: from ( "" ) ;
195
+ assert ! ( no_proxy. is_empty( ) ) ;
196
+ }
197
+
186
198
#[ test]
187
199
fn wildcard ( ) {
188
200
should_match ( "*" , "www.wikipedia.org" ) ;
Original file line number Diff line number Diff line change @@ -65,8 +65,10 @@ mod tests {
65
65
// parsing a comma separated string
66
66
let result: NoProxy = serde_json:: from_str ( & json) . unwrap ( ) ;
67
67
assert_eq ! ( proxy, result) ;
68
+ assert_eq ! ( result. content. len( ) , 2 ) ;
68
69
// parsing an array of strings
69
70
let result: NoProxy = serde_json:: from_str ( r#"["foo.bar", "1.2.3.4"]"# ) . unwrap ( ) ;
70
71
assert_eq ! ( proxy, result) ;
72
+ assert_eq ! ( result. content. len( ) , 2 ) ;
71
73
}
72
74
}
You can’t perform that action at this time.
0 commit comments