Allow InReplyTo to be a single item, not always an item collection
Fix tests
This commit is contained in:
parent
3cc5090015
commit
22a1b093fa
2 changed files with 26 additions and 11 deletions
13
decoding.go
13
decoding.go
|
@ -252,7 +252,7 @@ func JSONGetItem(data []byte, prop string) Item {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
case jsonparser.Array:
|
case jsonparser.Array:
|
||||||
fallthrough
|
return JSONGetItems(data, prop)
|
||||||
case jsonparser.Object:
|
case jsonparser.Object:
|
||||||
return JSONUnmarshalToItem(val)
|
return JSONUnmarshalToItem(val)
|
||||||
case jsonparser.Number:
|
case jsonparser.Number:
|
||||||
|
@ -322,9 +322,14 @@ func JSONGetItems(data []byte, prop string) ItemCollection {
|
||||||
}
|
}
|
||||||
}, prop)
|
}, prop)
|
||||||
case jsonparser.Object:
|
case jsonparser.Object:
|
||||||
// this should never happen :)
|
it.Append(JSONGetItem(data, prop))
|
||||||
case jsonparser.String:
|
case jsonparser.String:
|
||||||
it.Append(IRI(val))
|
if len(val) > 0 {
|
||||||
|
it.Append(IRI(val))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(it) == 0 {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
|
@ -509,7 +514,7 @@ func loadObject(data []byte, o *Object) error {
|
||||||
o.Preview = JSONGetItem(data, "preview")
|
o.Preview = JSONGetItem(data, "preview")
|
||||||
o.Image = JSONGetItem(data, "image")
|
o.Image = JSONGetItem(data, "image")
|
||||||
o.Updated = JSONGetTime(data, "updated")
|
o.Updated = JSONGetTime(data, "updated")
|
||||||
o.InReplyTo = JSONGetItems(data, "inReplyTo")
|
o.InReplyTo = JSONGetItem(data, "inReplyTo")
|
||||||
o.To = JSONGetItems(data, "to")
|
o.To = JSONGetItems(data, "to")
|
||||||
o.Audience = JSONGetItems(data, "audience")
|
o.Audience = JSONGetItems(data, "audience")
|
||||||
o.Bto = JSONGetItems(data, "bto")
|
o.Bto = JSONGetItems(data, "bto")
|
||||||
|
|
|
@ -259,6 +259,16 @@ var allTests = testMaps{
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"object_no_type": testPair{
|
||||||
|
expected: true,
|
||||||
|
blank: &pub.Object{},
|
||||||
|
result: &pub.Object{
|
||||||
|
ID: pub.ID("http://www.test.example/object/1"),
|
||||||
|
Name: pub.NaturalLanguageValues{{
|
||||||
|
pub.NilLangRef, pub.Content("A Simple, non-specific object without a type"),
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
"object_with_tags": testPair{
|
"object_with_tags": testPair{
|
||||||
expected: true,
|
expected: true,
|
||||||
blank: &pub.Object{},
|
blank: &pub.Object{},
|
||||||
|
@ -333,7 +343,7 @@ var allTests = testMaps{
|
||||||
ID: pub.ID("http://example.com/accounts/ana"),
|
ID: pub.ID("http://example.com/accounts/ana"),
|
||||||
Type: pub.PersonType,
|
Type: pub.PersonType,
|
||||||
Name: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("ana")}},
|
Name: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("ana")}},
|
||||||
PreferredUsername: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("ana")}},
|
PreferredUsername: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("Ana")}},
|
||||||
URL: pub.IRI("http://example.com/accounts/ana"),
|
URL: pub.IRI("http://example.com/accounts/ana"),
|
||||||
Outbox: &pub.OrderedCollection{
|
Outbox: &pub.OrderedCollection{
|
||||||
ID: "http://example.com/accounts/ana/outbox",
|
ID: "http://example.com/accounts/ana/outbox",
|
||||||
|
@ -377,6 +387,7 @@ var allTests = testMaps{
|
||||||
URL: pub.IRI("http://example.com/outbox?page=2"),
|
URL: pub.IRI("http://example.com/outbox?page=2"),
|
||||||
Current: pub.IRI("http://example.com/outbox?page=2"),
|
Current: pub.IRI("http://example.com/outbox?page=2"),
|
||||||
TotalItems: 1,
|
TotalItems: 1,
|
||||||
|
StartIndex: 100,
|
||||||
OrderedItems: pub.ItemCollection{
|
OrderedItems: pub.ItemCollection{
|
||||||
&pub.Object{
|
&pub.Object{
|
||||||
ID: pub.ID("http://example.com/outbox/53c6fb47"),
|
ID: pub.ID("http://example.com/outbox/53c6fb47"),
|
||||||
|
@ -394,12 +405,11 @@ var allTests = testMaps{
|
||||||
},
|
},
|
||||||
"natural_language_values": {
|
"natural_language_values": {
|
||||||
expected: true,
|
expected: true,
|
||||||
blank: &pub.NaturalLanguageValues{},
|
blank: &pub.NaturalLanguageValues{},
|
||||||
result: &pub.NaturalLanguageValues{
|
result: &pub.NaturalLanguageValues{
|
||||||
{
|
{
|
||||||
pub.NilLangRef, pub.Content(`
|
pub.NilLangRef, pub.Content([]byte{'\n','\t', '\t', '\n'}),
|
||||||
|
},
|
||||||
`)},
|
|
||||||
{pub.LangRef("en"), pub.Content("Ana got apples ⓐ")},
|
{pub.LangRef("en"), pub.Content("Ana got apples ⓐ")},
|
||||||
{pub.LangRef("fr"), pub.Content("Aná a des pommes ⒜")},
|
{pub.LangRef("fr"), pub.Content("Aná a des pommes ⒜")},
|
||||||
{pub.LangRef("ro"), pub.Content("Ana are mere")},
|
{pub.LangRef("ro"), pub.Content("Ana are mere")},
|
||||||
|
@ -414,7 +424,7 @@ var allTests = testMaps{
|
||||||
Object: &pub.Object{
|
Object: &pub.Object{
|
||||||
Type: pub.NoteType,
|
Type: pub.NoteType,
|
||||||
AttributedTo: pub.IRI("https://littr.git/api/accounts/anonymous"),
|
AttributedTo: pub.IRI("https://littr.git/api/accounts/anonymous"),
|
||||||
InReplyTo: pub.ItemCollection{pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff")},
|
InReplyTo: pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff"),
|
||||||
Content: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("<p>Hello world</p>")}},
|
Content: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("<p>Hello world</p>")}},
|
||||||
To: pub.ItemCollection{pub.IRI("https://www.w3.org/ns/activitystreams#Public")},
|
To: pub.ItemCollection{pub.IRI("https://www.w3.org/ns/activitystreams#Public")},
|
||||||
},
|
},
|
||||||
|
@ -430,7 +440,7 @@ var allTests = testMaps{
|
||||||
&pub.Object{
|
&pub.Object{
|
||||||
Type: pub.NoteType,
|
Type: pub.NoteType,
|
||||||
AttributedTo: pub.IRI("https://littr.git/api/accounts/anonymous"),
|
AttributedTo: pub.IRI("https://littr.git/api/accounts/anonymous"),
|
||||||
InReplyTo: pub.ItemCollection{pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff")},
|
InReplyTo: pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff"),
|
||||||
Content: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("<p>Hello world</p>")}},
|
Content: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("<p>Hello world</p>")}},
|
||||||
To: pub.ItemCollection{pub.IRI("https://www.w3.org/ns/activitystreams#Public")},
|
To: pub.ItemCollection{pub.IRI("https://www.w3.org/ns/activitystreams#Public")},
|
||||||
},
|
},
|
Reference in a new issue