Skip to content

Commit a03612a

Browse files
authored
Merge pull request #14 from T3pp31/codex/revise-stdin-input-trimming-logic
stdin入力で末尾改行のみを除去し先頭/末尾スペースを保持する修正
2 parents e47f24a + e70fb52 commit a03612a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/cli.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)