Skip to content

Commit 9ef20a7

Browse files
committed
use split_once
1 parent 5bcc2d5 commit 9ef20a7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/uu/chroot/src/chroot.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ struct Options {
5454
/// The `spec` must be of the form `[USER][:[GROUP]]`, otherwise an
5555
/// error is returned.
5656
fn parse_userspec(spec: &str) -> UResult<UserSpec> {
57-
let mut parts = spec.splitn(2, ':');
58-
match (parts.next(), parts.next()) {
57+
Ok(match spec.split_once(':') {
5958
// ""
60-
(Some(""), None) => Ok(UserSpec::NeitherGroupNorUser),
59+
None if spec == "" => UserSpec::NeitherGroupNorUser,
6160
// "usr"
62-
(Some(usr), None) => Ok(UserSpec::UserOnly(usr.to_string())),
61+
None => UserSpec::UserOnly(spec.to_string()),
6362
// ":"
64-
(Some(""), Some("")) => Ok(UserSpec::NeitherGroupNorUser),
63+
Some(("", "")) => UserSpec::NeitherGroupNorUser,
6564
// ":grp"
66-
(Some(""), Some(grp)) => Ok(UserSpec::GroupOnly(grp.to_string())),
65+
Some(("", grp)) => UserSpec::GroupOnly(grp.to_string()),
6766
// "usr:"
68-
(Some(usr), Some("")) => Ok(UserSpec::UserOnly(usr.to_string())),
67+
Some((usr, "")) => UserSpec::UserOnly(usr.to_string()),
6968
// "usr:grp"
70-
(Some(usr), Some(grp)) => Ok(UserSpec::UserAndGroup(usr.to_string(), grp.to_string())),
69+
Some((usr, grp)) => UserSpec::UserAndGroup(usr.to_string(), grp.to_string()),
70+
// BUG: this would never be reached. Should we check for another ':', or some invalid characters?
7171
// everything else
72-
_ => Err(ChrootError::InvalidUserspec(spec.to_string()).into()),
73-
}
72+
// _ => Err(ChrootError::InvalidUserspec(spec.to_string()).into()),
73+
})
7474
}
7575

7676
// Pre-condition: `list_str` is non-empty.

0 commit comments

Comments
 (0)