@cryptotaxi247 / kubo / commits / 33ad56e6d

commands: Safer type coercion when choosing marshaller

Matt Bell committed Nov 3, 2014 at 23:08 UTC 33ad56e6d0260e30b60a927e3e5be4efc7bb6b53
1 file changed +4 -3
commands/response.go
+4 -3
@@ -120,11 +120,12 @@ func (r *response) Marshal() ([]byte, error) {
120 return []byte{}, nil
121 }
122
123 - enc, ok := r.req.Option(EncShort)
124 - if !ok || enc.(string) == "" {
123 + enc, found := r.req.Option(EncShort)
124 + encStr, ok := enc.(string)
125 + if !found || !ok || encStr == "" {
126 return nil, fmt.Errorf("No encoding type was specified")
127 }
127 - encType := EncodingType(strings.ToLower(enc.(string)))
128 + encType := EncodingType(strings.ToLower(encStr))
129
130 marshaller, ok := marshallers[encType]
131 if !ok {