fn from_version_string(
version_string: &str,
) -> Result<Self, &'static str> {
- if version_string.is_empty() {
- return Err("version string is empty");
- }
-
let mut versions = HashSet::<Version>::new();
for piece in version_string.split(",") {
for p in expand_version_range(piece)? {
versions.insert(p);
}
+ } else if piece == "" {
+ continue;
} else {
let v = u32::from_str(piece).or(
Err("invalid protocol entry"),
return Err("protocol range value out of range");
}
+ if lower > higher {
+ return Err("protocol range is badly formed");
+ }
+
// We can use inclusive range syntax when it becomes stable.
let result = lower..higher + 1;
let mut parts = subproto.splitn(2, "=");
let name = match parts.next() {
+ Some("") => return Err("invalid protover entry"),
Some(n) => n,
None => return Err("invalid protover entry"),
};
Ok(result) => result,
Err(_) => continue,
};
-
for (protocol, versions) in this_vote {
let supported_vers: &mut HashMap<Version, usize> =
all_count.entry(protocol).or_insert(HashMap::new());
use super::Versions;
- assert_eq!(Err("version string is empty"), Versions::from_version_string(""));
assert_eq!(Err("invalid protocol entry"), Versions::from_version_string("a,b"));
assert_eq!(Err("invalid protocol entry"), Versions::from_version_string("1,!"));
use super::contains_only_supported_protocols;
assert_eq!(false, contains_only_supported_protocols(""));
- assert_eq!(false, contains_only_supported_protocols("Cons="));
+ assert_eq!(true, contains_only_supported_protocols("Cons="));
assert_eq!(true, contains_only_supported_protocols("Cons=1"));
assert_eq!(false, contains_only_supported_protocols("Cons=0"));
assert_eq!(false, contains_only_supported_protocols("Cons=0-1"));