Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
a05a1130
Commit
a05a1130
authored
6 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'onionk/rust-protocommas1'
parents
62401812
b91bc1ba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changes/bug27197
+3
-0
3 additions, 0 deletions
changes/bug27197
src/rust/protover/protoset.rs
+16
-17
16 additions, 17 deletions
src/rust/protover/protoset.rs
with
19 additions
and
17 deletions
changes/bug27197
0 → 100644
+
3
−
0
View file @
a05a1130
o Minor bugfixes (protover, rust):
- Reject extra commas in version string. Fixes bug 27197; bugfix on
0.3.3.3-alpha.
This diff is collapsed.
Click to expand it.
src/rust/protover/protoset.rs
+
16
−
17
View file @
a05a1130
...
...
@@ -352,23 +352,25 @@ impl FromStr for ProtoSet {
/// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("3-"));
/// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1-,4"));
///
/// //
Things which would get parsed into an _empty_ `ProtoSet` are,
/// //
however, legal, and result in an
empty `ProtoSet`:
/// //
An empty string is, however, legal, and results in an
/// // empty `ProtoSet`:
/// assert_eq!(Ok(ProtoSet::default()), ProtoSet::from_str(""));
/// assert_eq!(Ok(ProtoSet::default()), ProtoSet::from_str(",,,"));
/// #
/// # Ok(protoset)
/// # }
/// # fn main() { do_test(); } // wrap the test so we can use the ? operator
/// ```
fn
from_str
(
version_string
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
// If we were passed in an empty string, then return an empty ProtoSet.
if
version_string
.is_empty
()
{
return
Ok
(
Self
::
default
());
}
let
mut
pairs
:
Vec
<
(
Version
,
Version
)
>
=
Vec
::
new
();
let
pieces
:
::
std
::
str
::
Split
<
char
>
=
version_string
.split
(
','
);
for
p
in
pieces
{
if
p
.is_empty
()
{
continue
;
}
else
if
p
.contains
(
'-'
)
{
if
p
.contains
(
'-'
)
{
let
mut
pair
=
p
.splitn
(
2
,
'-'
);
let
low
=
pair
.next
()
.ok_or
(
ProtoverError
::
Unparseable
)
?
;
...
...
@@ -377,24 +379,14 @@ impl FromStr for ProtoSet {
let
lo
:
Version
=
low
.parse
()
.or
(
Err
(
ProtoverError
::
Unparseable
))
?
;
let
hi
:
Version
=
high
.parse
()
.or
(
Err
(
ProtoverError
::
Unparseable
))
?
;
if
lo
==
u32
::
MAX
||
hi
==
u32
::
MAX
{
return
Err
(
ProtoverError
::
ExceedsMax
);
}
pairs
.push
((
lo
,
hi
));
}
else
{
let
v
:
u32
=
p
.parse
()
.or
(
Err
(
ProtoverError
::
Unparseable
))
?
;
if
v
==
u32
::
MAX
{
return
Err
(
ProtoverError
::
ExceedsMax
);
}
pairs
.push
((
v
,
v
));
}
}
// If we were passed in an empty string, or
// simply a comma, or a pile of commas, then return an empty ProtoSet.
if
pairs
.len
()
==
0
{
return
Ok
(
ProtoSet
::
default
());
}
ProtoSet
::
from_slice
(
&
pairs
[
..
])
}
}
...
...
@@ -558,6 +550,13 @@ mod test {
assert_eq!
(
Err
(
ProtoverError
::
Unparseable
),
ProtoSet
::
from_str
(
"-1"
));
}
#[test]
fn
test_versions_from_str_commas
()
{
assert_eq!
(
Err
(
ProtoverError
::
Unparseable
),
ProtoSet
::
from_str
(
","
));
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_hyphens
()
{
assert_eq!
(
Err
(
ProtoverError
::
Unparseable
),
ProtoSet
::
from_str
(
"--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