diff --git a/Cargo.toml b/Cargo.toml index bdac1a2..be364be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "moongreet" -version = "0.3.0" +version = "0.3.1" edition = "2024" description = "A greetd greeter for Wayland with GTK4 and Layer Shell" license = "MIT" diff --git a/src/greeter.rs b/src/greeter.rs index be451d1..384f050 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -47,14 +47,16 @@ fn split_shell_words(s: &str) -> Option> { } '\\' if in_double => { // In double quotes, backslash escapes the next char - if let Some(next) = chars.next() { - current.push(next); + match chars.next() { + Some(next) => current.push(next), + None => return None, // Trailing backslash } } '\\' if !in_single && !in_double => { // Outside quotes, backslash escapes the next char - if let Some(next) = chars.next() { - current.push(next); + match chars.next() { + Some(next) => current.push(next), + None => return None, // Trailing backslash } } c if c.is_whitespace() && !in_single && !in_double => { @@ -1189,6 +1191,12 @@ mod tests { ); } + #[test] + fn shell_words_trailing_backslash() { + assert_eq!(split_shell_words(r"foo\"), None); + assert_eq!(split_shell_words(r#""foo\"#), None); + } + // -- login_worker tests -- // These use a real Unix socket pair via UnixListener to simulate greetd. diff --git a/src/users.rs b/src/users.rs index e4f65ef..2f9e6c7 100644 --- a/src/users.rs +++ b/src/users.rs @@ -30,12 +30,12 @@ pub struct User { } impl User { - /// Return the display name (GECOS if available, otherwise username). + /// Return the display name (first GECOS subfield if available, otherwise username). pub fn display_name(&self) -> &str { if self.gecos.is_empty() { &self.username } else { - &self.gecos + self.gecos.split(',').next().unwrap_or(&self.username) } } } @@ -150,6 +150,17 @@ mod tests { assert_eq!(users[0].home, PathBuf::from("/home/testuser")); } + #[test] + fn gecos_subfield_trimmed() { + let dir = tempfile::tempdir().unwrap(); + let path = make_passwd( + dir.path(), + "testuser:x:1000:1000:Test User,Room 123,555-1234:/home/testuser:/bin/bash\n", + ); + let users = get_users(Some(&path)); + assert_eq!(users[0].display_name(), "Test User"); + } + #[test] fn skip_system_users() { let dir = tempfile::tempdir().unwrap();