rustfs_replication/
tagging.rs1use std::collections::HashMap;
16
17use url::form_urlencoded;
18
19pub struct ReplicationTagFilter;
20
21impl ReplicationTagFilter {
22 pub fn decode_tags_to_map(tags: &str) -> HashMap<String, String> {
23 decode_tags_to_map(tags)
24 }
25}
26
27pub fn decode_tags_to_map(tags: &str) -> HashMap<String, String> {
28 let mut list = HashMap::new();
29
30 for (k, v) in form_urlencoded::parse(tags.as_bytes()) {
31 if k.is_empty() {
32 continue;
33 }
34
35 list.insert(k.to_string(), v.to_string());
36 }
37
38 list
39}
40
41#[cfg(test)]
42mod tests {
43 use super::{ReplicationTagFilter, decode_tags_to_map};
44
45 #[test]
46 fn decode_tags_to_map_preserves_bucket_tagging_parser_behavior() {
47 let tags = decode_tags_to_map("env=prod&encoded=a%2Fb&=ignored");
48
49 assert_eq!(tags.get("env").map(String::as_str), Some("prod"));
50 assert_eq!(tags.get("encoded").map(String::as_str), Some("a/b"));
51 assert!(!tags.contains_key(""));
52 }
53
54 #[test]
55 fn replication_tag_filter_uses_shared_parser() {
56 let tags = ReplicationTagFilter::decode_tags_to_map("env=prod");
57
58 assert_eq!(tags.get("env").map(String::as_str), Some("prod"));
59 }
60}