Skip to content

Commit 918fb46

Browse files
squellbjorn3
andcommitted
much more readable suffix checking
Co-authored-by: bjorn3 <[email protected]>
1 parent 47805ca commit 918fb46

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/sudoers/tokens.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ pub struct Username(pub SudoString);
1313
impl Token for Username {
1414
fn construct(text: String) -> Result<Self, String> {
1515
// if a '$' occurs in a username, it has to be the final character
16-
if let Some((_, "")) | None = text.split_once('$') {
17-
SudoString::new(text)
18-
.map_err(|e| e.to_string())
19-
.map(Username)
20-
} else {
21-
Err("embedded $ in username".to_string())
16+
if text.strip_suffix('$').unwrap_or(&text).contains('$') {
17+
return Err("embedded $ in username".to_string());
2218
}
19+
20+
SudoString::new(text)
21+
.map_err(|e| e.to_string())
22+
.map(Username)
2323
}
2424

2525
fn accept(c: char) -> bool {

0 commit comments

Comments
 (0)