Skip to content

Commit 09eb913

Browse files
authored
Fix 404 error when an exact bundle key is given (#4)
`KeyMatch` always turned the `target` to lowercase, so an exact match would return a lowercase version of what was entered by the user. This resulted in `404` errors from the API for `details` and `download` commands.
1 parent bf3ea3f commit 09eb913

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/key_match.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl KeyMatch {
1010
pub fn new(keys: Vec<String>, target: &str) -> Self {
1111
Self {
1212
keys,
13-
target: target.to_lowercase(),
13+
target: target.to_owned(),
1414
}
1515
}
1616

@@ -28,14 +28,24 @@ impl KeyMatch {
2828
return vec![self.target.clone()];
2929
}
3030

31+
let lowercase_target = self.target.to_lowercase();
3132
self.keys
3233
.iter()
33-
.filter(|k| k.to_lowercase().starts_with(&self.target))
34+
.filter(|k| k.to_lowercase().starts_with(&lowercase_target))
3435
.cloned()
3536
.collect()
3637
}
3738
}
3839

40+
#[test]
41+
fn test_exact_match() {
42+
let keys = vec!["1AaAaA".to_owned(), "2BbBbB".to_owned()];
43+
let target = "1AaAaA".to_owned();
44+
45+
let key_match = KeyMatch::new(keys, &target);
46+
assert_eq!(key_match.get_matches(), vec!["1AaAaA".to_owned()]);
47+
}
48+
3949
#[test]
4050
fn test_single_match() {
4151
let keys = vec!["1aAa".to_owned(), "2bbbb".to_owned()];

0 commit comments

Comments
 (0)