Skip to content

fix: stdin入力で前後スペースが消える不具合を修正#18

Merged
T3pp31 merged 2 commits into
mainfrom
fix/cli-stdin-preserve-spaces
May 29, 2026
Merged

fix: stdin入力で前後スペースが消える不具合を修正#18
T3pp31 merged 2 commits into
mainfrom
fix/cli-stdin-preserve-spaces

Conversation

@T3pp31
Copy link
Copy Markdown
Owner

@T3pp31 T3pp31 commented May 29, 2026

概要

CLI の encrypt / decrypt で、stdin 入力--text 引数の暗号化結果が一致しない不具合を修正しました。

原因

get_input_text の stdin 経路および対話モードの prompt_for_textinput.trim() により前後の空白まで除去していました。一方 --text はそのまま渡すため、同じ文字列でも結果が異なっていました。

入力 修正前 修正後
--text " Hello " Khoor Khoor
stdin Hello + Enter Khoor Khoor

trim_trailing_newline はテスト用(#[cfg(test)])に閉じ込められており、本番の stdin では使われていませんでした(過去 PR #14 で一度修正された経緯がありますが、リファクタ後に trim() に戻っていました)。

変更内容

  • get_input_text / prompt_for_text: trim()trim_trailing_newline(末尾 \n / \r のみ除去、スペースは保持)
  • trim_trailing_newline を本番コードでも利用可能に変更
  • 回帰防止: stdin と --text の出力が一致することを検証する統合テストを追加

テスト計画

  • cargo test(全テスト)
  • cargo test test_cli_encrypt_stdin_matches_text_arg_for_surrounding_spaces --test cli_output_tests
  • 手動確認: printf ' Hello \n' | cargo run -- encrypt --shift 3cargo run -- encrypt --text " Hello " --shift 3 の出力が一致すること

補足(スコープ外)

  • ファイル入力は末尾改行を含めてそのまま読み込むため、stdin とは末尾改行の扱いが異なる場合があります(従来どおり)。
  • --safe なしでは空白のみの入力はエラーにしません(safe API の仕様差)。

Made with Cursor

T3pp31 and others added 2 commits May 30, 2026 00:13
get_input_text と対話モードの prompt_for_text で全面 trim() していたため、
--text 引数と stdin 入力で暗号化結果が一致しない問題を解消する。
末尾の改行のみ trim_trailing_newline で除去し、スペースは保持する。
回帰防止の CLI 統合テストを追加。

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@T3pp31 T3pp31 merged commit fde906d into main May 29, 2026
1 check passed
@T3pp31 T3pp31 deleted the fix/cli-stdin-preserve-spaces branch May 29, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant