Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum nil pointer safety #370

Merged
merged 3 commits into from
Jul 27, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Prevent panic when trying to serialize nil pointer in Enum
  • Loading branch information
sfriedel committed Jul 27, 2018
commit 4c649e36c293b6e6b9d68a7cdc2cd683bc1195db
5 changes: 4 additions & 1 deletion definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,10 @@ func (gt *Enum) Values() []*EnumValueDefinition {
}
func (gt *Enum) Serialize(value interface{}) interface{} {
v := value
if reflect.ValueOf(v).Kind() == reflect.Ptr {
rv := reflect.ValueOf(v)
if kind := rv.Kind(); kind == reflect.Ptr && rv.IsNil() {
return nil
} else if kind == reflect.Ptr {
v = reflect.Indirect(reflect.ValueOf(v)).Interface()
}
if enumValue, ok := gt.getValueLookup()[v]; ok {
Expand Down