Skip to content

Commit

Permalink
Merge pull request #166 from pabigot/pabigot/20220905a
Browse files Browse the repository at this point in the history
Fix topic matches with single-level wildcard
  • Loading branch information
fpagliughi authored Sep 17, 2022
2 parents e9e4b80 + e6fc437 commit 004554f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,17 @@ impl TopicFilter {
false
}
else {
let mut saw_wc = false;
for i in 0..n {
if fields[i] == "#" {
saw_wc = true;
break;
}
if fields[i] != "+" && fields[i] != top_fields[i] {
return false;
}
}
true
saw_wc || n == top_fields.len()
}
}
}
Expand Down Expand Up @@ -526,8 +528,14 @@ mod tests {
const FILTER2: &str = "some/+/thing";
let filter = TopicFilter::new(FILTER2).unwrap();
assert!(filter.is_match("some/topic/thing"));
assert!(!filter.is_match("some/topic/plus/thing"));

let s = format!("{}", filter);
assert_eq!(s, FILTER2);

const FILTER3: &str = "some/+";
let filter = TopicFilter::new(FILTER3).unwrap();
assert!(filter.is_match("some/thing"));
assert!(!filter.is_match("some/thing/plus"));
}
}

0 comments on commit 004554f

Please sign in to comment.