Skip to content

Return nil from FromString on invalid input instead of panicking#7

Open
SAY-5 wants to merge 1 commit into
rushysloth:mainfrom
SAY-5:fix-fromstring-nil-panic
Open

Return nil from FromString on invalid input instead of panicking#7
SAY-5 wants to merge 1 commit into
rushysloth:mainfrom
SAY-5:fix-fromstring-nil-panic

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 18, 2026

Copy link
Copy Markdown

FromString calls ToRuneArray, which returns nil for any input that fails validation, and then immediately indexes arr[0]. So a 13-char string whose characters aren't in the alphabet (e.g. FromString("zzzzzzzzzzzzz")), an empty string, or any wrong-length string panics with index out of range instead of failing gracefully.

This guards the nil case and returns nil, matching the existing // TODO: Throw error intent in ToRuneArray. Added a regression test covering a valid round-trip plus the invalid inputs.

Fixes #6

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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.

FromString panics (index out of range) on syntactically-valid 13-char input with out-of-range first character

1 participant