Skip to content
Snippets Groups Projects
Commit cc93f175 authored by cypherpunks's avatar cypherpunks
Browse files

rust/protover: fix hyphen parsing bug in ProtoSet::from_str()

It was parsing "1-2-3" as if it were 1-2, ignoring the 2nd hyphen
and everything after.

Introduced in d1820c15.

Fixes #27164; bugfix on 0.3.3.1-alpha.
parent 936e2aa0
No related branches found
No related tags found
No related merge requests found
o Minor bugfixes (rust):
- Protover parsing was ignoring a 2nd hyphen and everything after it,
accepting entries like "Link=1-5-foo". Fixes bug 27164; bugfix on
0.3.3.1-alpha.
......@@ -348,7 +348,7 @@ impl FromStr for ProtoSet {
if p.is_empty() {
continue;
} else if p.contains('-') {
let mut pair = p.split('-');
let mut pair = p.splitn(2, '-');
let low = pair.next().ok_or(ProtoverError::Unparseable)?;
let high = pair.next().ok_or(ProtoverError::Unparseable)?;
......@@ -538,6 +538,18 @@ mod test {
assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-1"));
}
#[test]
fn test_versions_from_str_hyphens() {
assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("--1"));
assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-1-2"));
assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1--2"));
}
#[test]
fn test_versions_from_str_triple() {
assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1-2-3"));
}
#[test]
fn test_versions_from_str_1exclam() {
assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1,!"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment