File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,6 +87,16 @@ mod name_list {
8787 if value. is_empty ( ) {
8888 return Ok ( Self ( Vec :: new ( ) ) ) ;
8989 }
90+
91+ // Some legacy SSH implementations append a comma to name-lists.
92+ // OpenSSH accepts this, so tolerate exactly one trailing comma for
93+ // interoperability while continuing to reject all other empty
94+ // entries.
95+ let value = value
96+ . strip_suffix ( ',' )
97+ . filter ( |value| !value. is_empty ( ) )
98+ . unwrap_or ( value) ;
99+
90100 Ok ( Self ( value. split ( ',' ) . try_fold (
91101 Vec :: new ( ) ,
92102 |mut list, name| {
@@ -151,6 +161,19 @@ mod name_list {
151161 // the zero-length whole-list case is allowed.
152162 assert ! ( NameList :: from_encoded_string( "a,,b" ) . is_err( ) ) ;
153163 }
164+
165+ #[ test]
166+ fn name_list_accepts_single_trailing_comma ( ) {
167+ let nl = NameList :: from_encoded_string ( "a,b," ) . unwrap ( ) ;
168+ assert_eq ! ( nl. 0 , vec![ "a" , "b" ] ) ;
169+ assert_eq ! ( nl. as_encoded_string( ) , "a,b" ) ;
170+ }
171+
172+ #[ test]
173+ fn name_list_rejects_other_empty_trailing_entries ( ) {
174+ assert ! ( NameList :: from_encoded_string( "," ) . is_err( ) ) ;
175+ assert ! ( NameList :: from_encoded_string( "a,," ) . is_err( ) ) ;
176+ }
154177 }
155178}
156179
You can’t perform that action at this time.
0 commit comments