aboutsummaryrefslogtreecommitdiff
path: root/src/rust
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-08-03 08:54:03 -0400
committerNick Mathewson <nickm@torproject.org>2020-08-03 08:54:03 -0400
commitd1fda62d11139830b0d81d56d0dfd372237d0be6 (patch)
treebcd54004a203fe54e8009256929fc2b408d82f54 /src/rust
parent3e3b0b0443b6486553e5cfc18a23a8d7cb7ae4c4 (diff)
parent32b33c0d21ce471d735abbedc26d26998238c380 (diff)
downloadtor-d1fda62d11139830b0d81d56d0dfd372237d0be6.tar.gz
tor-d1fda62d11139830b0d81d56d0dfd372237d0be6.zip
Merge remote-tracking branch 'tor-gitlab/mr/94'
Diffstat (limited to 'src/rust')
-rw-r--r--src/rust/protover/protover.rs17
-rw-r--r--src/rust/protover/tests/protover.rs13
2 files changed, 11 insertions, 19 deletions
diff --git a/src/rust/protover/protover.rs b/src/rust/protover/protover.rs
index 076cd5301e..550732734c 100644
--- a/src/rust/protover/protover.rs
+++ b/src/rust/protover/protover.rs
@@ -253,6 +253,11 @@ impl FromStr for ProtoEntry {
/// Otherwise, the `Err` value of this `Result` is a `ProtoverError`.
fn from_str(protocol_entry: &str) -> Result<ProtoEntry, ProtoverError> {
let mut proto_entry: ProtoEntry = ProtoEntry::default();
+
+ if protocol_entry.is_empty() {
+ return Ok(proto_entry);
+ }
+
let entries = protocol_entry.split(' ');
for entry in entries {
@@ -501,6 +506,10 @@ impl UnvalidatedProtoEntry {
) -> Result<Vec<(&'a str, &'a str)>, ProtoverError> {
let mut protovers: Vec<(&str, &str)> = Vec::new();
+ if protocol_string.is_empty() {
+ return Ok(protovers);
+ }
+
for subproto in protocol_string.split(' ') {
let mut parts = subproto.splitn(2, '=');
@@ -859,7 +868,8 @@ mod test {
#[test]
fn test_protoentry_from_str_empty() {
- assert_protoentry_is_unparseable!("");
+ assert_protoentry_is_parseable!("");
+ assert!(UnvalidatedProtoEntry::from_str("").is_ok());
}
#[test]
@@ -883,11 +893,6 @@ mod test {
}
#[test]
- fn test_protoentry_from_str_() {
- assert_protoentry_is_unparseable!("");
- }
-
- #[test]
fn test_protoentry_all_supported_single_protocol_single_version() {
let protocol: UnvalidatedProtoEntry = "Cons=1".parse().unwrap();
let unsupported: Option<UnvalidatedProtoEntry> = protocol.all_supported();
diff --git a/src/rust/protover/tests/protover.rs b/src/rust/protover/tests/protover.rs
index 942fe3c6ab..c97810a6f2 100644
--- a/src/rust/protover/tests/protover.rs
+++ b/src/rust/protover/tests/protover.rs
@@ -70,18 +70,6 @@ fn protocol_all_supported_with_one_value() {
}
#[test]
-#[should_panic]
-fn parse_protocol_unvalidated_with_empty() {
- let _: UnvalidatedProtoEntry = "".parse().unwrap();
-}
-
-#[test]
-#[should_panic]
-fn parse_protocol_validated_with_empty() {
- let _: UnvalidatedProtoEntry = "".parse().unwrap();
-}
-
-#[test]
fn protocol_all_supported_with_three_values() {
let protocols: UnvalidatedProtoEntry = "LinkAuth=1 Microdesc=1-2 Relay=2".parse().unwrap();
let unsupported: Option<UnvalidatedProtoEntry> = protocols.all_supported();
@@ -156,7 +144,6 @@ fn parse_protocol_with_unexpected_characters() {
}
#[test]
-#[should_panic]
fn protover_compute_vote_returns_empty_for_empty_string() {
let protocols: &[UnvalidatedProtoEntry] = &["".parse().unwrap()];
let listed = ProtoverVote::compute(protocols, &1);