Skip to content

Commit 57410a2

Browse files
authored
Merge pull request #9 from T3pp31/claude/code-review-improvements-rhWJj
Refactor CLI args and add input validation with shift range support
2 parents 9fdfe79 + d647a96 commit 57410a2

9 files changed

Lines changed: 495 additions & 89 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "caesar_cipher_enc_dec"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
edition = "2021"
55
description = "can easily use caesar cipher"
66
license = "MIT"

src/caesar_cipher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl std::fmt::Display for CipherError {
5252
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5353
match self {
5454
CipherError::InvalidShift(msg) => write!(f, "Invalid shift value: {}", msg),
55-
CipherError::EmptyText => write!(f, "Input text cannot be empty"),
55+
CipherError::EmptyText => write!(f, "Input text cannot be empty or whitespace-only"),
5656
}
5757
}
5858
}
@@ -143,7 +143,7 @@ pub fn decrypt(text: &str, shift: i16) -> String {
143143
/// assert!(encrypt_safe("Hello", 26).is_err());
144144
/// ```
145145
pub fn encrypt_safe(text: &str, shift: i16) -> Result<String, CipherError> {
146-
if text.is_empty() {
146+
if text.trim().is_empty() {
147147
return Err(CipherError::EmptyText);
148148
}
149149

@@ -185,7 +185,7 @@ pub fn encrypt_safe(text: &str, shift: i16) -> Result<String, CipherError> {
185185
/// assert_eq!(result, "Hello");
186186
/// ```
187187
pub fn decrypt_safe(text: &str, shift: i16) -> Result<String, CipherError> {
188-
if text.is_empty() {
188+
if text.trim().is_empty() {
189189
return Err(CipherError::EmptyText);
190190
}
191191

0 commit comments

Comments
 (0)