Skip to content

Commit

Permalink
Merge pull request #188 from salewski/ads/parse-spec-ignore-blank-spec
Browse files Browse the repository at this point in the history
filter::parse_spec() ignore bogon empty, blank (sub)strings
  • Loading branch information
jplatte committed Dec 7, 2020
2 parents a36b72d + 780e7c5 commit eb50f9d
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/filter/mod.rs
Expand Up @@ -299,7 +299,7 @@ fn parse_spec(spec: &str) -> (Vec<Directive>, Option<inner::Filter>) {
return (dirs, None);
}
if let Some(m) = mods {
for s in m.split(',') {
for s in m.split(',').map(|ss| ss.trim()) {
if s.is_empty() {
continue;
}
Expand Down Expand Up @@ -737,6 +737,55 @@ mod tests {
assert!(filter.is_none());
}

#[test]
fn parse_spec_empty_level_isolated() {
// test parse_spec with "" as log level (and the entire spec str)
let (dirs, filter) = parse_spec(""); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated() {
// test parse_spec with a white-space-only string specified as the log
// level (and the entire spec str)
let (dirs, filter) = parse_spec(" "); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated_comma_only() {
// The spec should contain zero or more comma-separated string slices,
// so a comma-only string should be interpretted as two empty strings
// (which should both be treated as invalid, so ignored).
let (dirs, filter) = parse_spec(","); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated_comma_blank() {
// The spec should contain zero or more comma-separated string slices,
// so this bogus spec should be interpretted as containing one empty
// string and one blank string. Both should both be treated as
// invalid, so ignored.
let (dirs, filter) = parse_spec(", "); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated_blank_comma() {
// The spec should contain zero or more comma-separated string slices,
// so this bogus spec should be interpretted as containing one blank
// string and one empty string. Both should both be treated as
// invalid, so ignored.
let (dirs, filter) = parse_spec(" ,"); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_global() {
// test parse_spec with no crate
Expand Down

0 comments on commit eb50f9d

Please sign in to comment.