fix: stdin入力で前後スペースが消える不具合を修正#18
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
CLI の
encrypt/decryptで、stdin 入力と--text引数の暗号化結果が一致しない不具合を修正しました。原因
get_input_textの stdin 経路および対話モードのprompt_for_textがinput.trim()により前後の空白まで除去していました。一方--textはそのまま渡すため、同じ文字列でも結果が異なっていました。--text " Hello "KhoorKhoorHello+ EnterKhoorKhoortrim_trailing_newlineはテスト用(#[cfg(test)])に閉じ込められており、本番の stdin では使われていませんでした(過去 PR #14 で一度修正された経緯がありますが、リファクタ後にtrim()に戻っていました)。変更内容
get_input_text/prompt_for_text:trim()→trim_trailing_newline(末尾\n/\rのみ除去、スペースは保持)trim_trailing_newlineを本番コードでも利用可能に変更--textの出力が一致することを検証する統合テストを追加テスト計画
cargo test(全テスト)cargo test test_cli_encrypt_stdin_matches_text_arg_for_surrounding_spaces --test cli_output_testsprintf ' Hello \n' | cargo run -- encrypt --shift 3とcargo run -- encrypt --text " Hello " --shift 3の出力が一致すること補足(スコープ外)
--safeなしでは空白のみの入力はエラーにしません(safe API の仕様差)。Made with Cursor