diff options
author | cypherpunks <cypherpunks@torproject.org> | 2018-08-07 00:45:33 +0000 |
---|---|---|
committer | cypherpunks <cypherpunks@torproject.org> | 2018-08-17 13:27:24 +0000 |
commit | cc93f175ed6f7495b4d50cdaad0527f718da77f5 (patch) | |
tree | c4741c2523e9bf3da2bcd3206c3db2cfa3fe4651 /src/rust/protover | |
parent | 936e2aa0de6edb0578e18ad0760a67ad64a448d4 (diff) | |
download | tor-cc93f175ed6f7495b4d50cdaad0527f718da77f5.tar.gz tor-cc93f175ed6f7495b4d50cdaad0527f718da77f5.zip |
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 d1820c1516a31a149fc51a9e5126bf899e4c4e08.
Fixes #27164; bugfix on 0.3.3.1-alpha.
Diffstat (limited to 'src/rust/protover')
-rw-r--r-- | src/rust/protover/protoset.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/rust/protover/protoset.rs b/src/rust/protover/protoset.rs index 4afc50edf8..61b21ede98 100644 --- a/src/rust/protover/protoset.rs +++ b/src/rust/protover/protoset.rs @@ -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)?; @@ -539,6 +539,18 @@ mod test { } #[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,!")); } |