File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -179,11 +179,15 @@ fn get_input_text(
179179 )
180180 . into ( ) ) ;
181181 }
182- Ok ( input . trim ( ) . to_string ( ) )
182+ Ok ( trim_trailing_newline ( & input ) . to_string ( ) )
183183 }
184184 }
185185}
186186
187+ fn trim_trailing_newline ( input : & str ) -> & str {
188+ input. trim_end_matches ( [ '\n' , '\r' ] )
189+ }
190+
187191/// Outputs the result to either a file or stdout
188192///
189193/// This function handles outputting the cipher result to the specified destination.
@@ -396,6 +400,13 @@ mod tests {
396400 . contains( "Cannot specify both text and file" ) ) ;
397401 }
398402
403+ #[ test]
404+ fn test_trim_trailing_newline_preserves_leading_and_trailing_spaces ( ) {
405+ let input = " keep spaces \n " ;
406+ let result = trim_trailing_newline ( input) ;
407+ assert_eq ! ( result, " keep spaces " ) ;
408+ }
409+
399410 #[ test]
400411 fn test_output_result_to_file ( ) {
401412 let temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments