Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscriber: fix issue with EnvFilter::builder().parse #2052

Merged
merged 2 commits into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions tracing-subscriber/src/filter/env/builder.rs
Expand Up @@ -133,16 +133,17 @@ impl Builder {
/// Returns a new [`EnvFilter`] from the directives in the given string,
/// *ignoring* any that are invalid.
pub fn parse_lossy<S: AsRef<str>>(&self, dirs: S) -> EnvFilter {
let directives =
dirs.as_ref()
.split(',')
.filter_map(|s| match Directive::parse(s, self.regex) {
Ok(d) => Some(d),
Err(err) => {
eprintln!("ignoring `{}`: {}", s, err);
None
}
});
let directives = dirs
.as_ref()
.split(',')
.filter(|s| !s.is_empty())
.filter_map(|s| match Directive::parse(s, self.regex) {
Ok(d) => Some(d),
Err(err) => {
eprintln!("ignoring `{}`: {}", s, err);
None
}
});
self.from_directives(directives)
}

Expand All @@ -155,6 +156,7 @@ impl Builder {
}
let directives = dirs
.split(',')
.filter(|s| !s.is_empty())
.map(|s| Directive::parse(s, self.regex))
.collect::<Result<Vec<_>, _>>()?;
Ok(self.from_directives(directives))
Expand Down
8 changes: 8 additions & 0 deletions tracing-subscriber/src/filter/env/mod.rs
Expand Up @@ -920,4 +920,12 @@ mod tests {
[span2{bar=2 baz=false}],crate2[{quux=\"quuux\"}]=debug",
);
}

#[test]
fn parse_empty_string() {
// There is no corresponding test for [`Builder::parse_lossy`] as failed
// parsing does not produce any observable side effects. If this test fails
// check that [`Builder::parse_lossy`] is behaving correctly as well.
assert!(EnvFilter::builder().parse("").is_ok());
}
}