Closed Roytangrb closed 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.
nil
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
reflect.ValueOf(nil).Interface()
reflect.Zero(reflect.ValueOf(nil).Type()).Interface()
To fix: return zero value of string ("") instead coz String Tranformer is guaranteed to return string
""
fix https://github.com/AlecAivazis/survey/issues/329
Nice catch! Thanks for submitting a fix
TranformString should not return
nil
on zero value, otherwisenil
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()
andreflect.Zero(reflect.ValueOf(nil).Type()).Interface()
will cause program to panicTo fix: return zero value of string (
""
) instead coz String Tranformer is guaranteed to return stringfix https://github.com/AlecAivazis/survey/issues/329