Be consistent in how we encode stringy types
Namely as []byte slices
This commit is contained in:
parent
525748448c
commit
f00af9750d
2
iri.go
2
iri.go
|
@ -98,7 +98,7 @@ func (i *IRI) GobDecode(data []byte) error {
|
|||
// NOTE(marius): this behaviour diverges from vanilla gob package
|
||||
return nil
|
||||
}
|
||||
var bb string
|
||||
var bb []byte
|
||||
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -332,7 +332,7 @@ func TestIRI_GobDecode(t *testing.T) {
|
|||
{
|
||||
name: "some iri",
|
||||
i: "https://example.com",
|
||||
data: gobValue("https://example.com"),
|
||||
data: gobValue([]byte("https://example.com")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
|
8
link.go
8
link.go
|
@ -3,9 +3,6 @@ package activitypub
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/valyala/fastjson"
|
||||
)
|
||||
|
||||
|
@ -214,6 +211,9 @@ func gobDecodeUint(i *uint, data []byte) error {
|
|||
}
|
||||
|
||||
func (l *Link) GobDecode(data []byte) error {
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
mm := make(map[string][]byte)
|
||||
g := gob.NewDecoder(bytes.NewReader(data))
|
||||
if err := g.Decode(&mm); err != nil {
|
||||
|
@ -264,5 +264,5 @@ func (l *Link) GobDecode(data []byte) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *l))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -642,7 +642,7 @@ func TestLangRef_GobDecode(t *testing.T) {
|
|||
{
|
||||
name: "some text",
|
||||
l: LangRef("ana are"),
|
||||
data: gobValue([]byte{'a', 'n', 'a', ' ', 'a', 'r', 'e'}),
|
||||
data: gobValue([]byte("ana are")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func (a *ActivityVocabularyType) GobDecode(data []byte) error {
|
|||
// NOTE(marius): this behaviour diverges from vanilla gob package
|
||||
return nil
|
||||
}
|
||||
var bb string
|
||||
var bb []byte
|
||||
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ func (m *MimeType) GobDecode(data []byte) error {
|
|||
// NOTE(marius): this behaviour diverges from vanilla gob package
|
||||
return nil
|
||||
}
|
||||
var bb string
|
||||
var bb []byte
|
||||
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&bb); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -377,7 +377,7 @@ func TestMimeType_GobDecode(t *testing.T) {
|
|||
{
|
||||
name: "some mime-type",
|
||||
m: "application/json",
|
||||
data: gobValue("application/json"),
|
||||
data: gobValue([]byte("application/json")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ func TestActivityVocabularyType_GobDecode(t *testing.T) {
|
|||
{
|
||||
name: "some activity type",
|
||||
t: PersonType,
|
||||
data: gobValue("Person"),
|
||||
data: gobValue([]byte("Person")),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
|
Reference in a new issue