Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
5af03c1e
Commit
5af03c1e
authored
Feb 15, 2018
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
rust protover: match the C implementation on empty-str cases
Empty versions lists are permitted; empty keywords are not.
parent
b58a2feb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/rust/protover/protover.rs
+8
-7
8 additions, 7 deletions
src/rust/protover/protover.rs
with
8 additions
and
7 deletions
src/rust/protover/protover.rs
+
8
−
7
View file @
5af03c1e
...
...
@@ -193,10 +193,6 @@ impl Versions {
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
(
","
)
{
...
...
@@ -204,6 +200,8 @@ impl Versions {
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"
),
...
...
@@ -456,6 +454,10 @@ fn expand_version_range(range: &str) -> Result<Range<u32>, &'static str> {
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
;
...
...
@@ -583,6 +585,7 @@ fn parse_protocols_from_string_with_no_validation<'a>(
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"
),
};
...
...
@@ -650,7 +653,6 @@ pub fn compute_vote(
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
());
...
...
@@ -794,7 +796,6 @@ mod test {
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,!"
));
...
...
@@ -838,7 +839,7 @@ mod test {
use
super
::
contains_only_supported_protocols
;
assert_eq!
(
false
,
contains_only_supported_protocols
(
""
));
assert_eq!
(
fals
e
,
contains_only_supported_protocols
(
"Cons="
));
assert_eq!
(
tru
e
,
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"
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment