AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.08k stars 351 forks source link

fix(transform): fix nil returned by TransformString #330

Closed Roytangrb closed 3 years ago

Roytangrb commented 3 years ago

TranformString should not return nil on zero value, otherwise nil will be passed to next Tranformer if there are more than 1 Transformer in ComposeTransformers.

In next TranformString, while checking if if value is zero at https://github.com/AlecAivazis/survey/blob/e64d9b644fb7d85d69cd3e33a92a43ee706c1b6f/validate.go#L86

reflect.ValueOf(nil).Interface() and reflect.Zero(reflect.ValueOf(nil).Type()).Interface()will cause program to panic

To fix: return zero value of string ("") instead coz String Tranformer is guaranteed to return string

fix https://github.com/AlecAivazis/survey/issues/329

AlecAivazis commented 3 years ago

Nice catch! Thanks for submitting a fix