mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-23 02:32:12 +00:00
[bugfix] Fix error extracting status content: no content found
(#598)
* don't return error if no content found in Activity * add test for content extraction * go fmt
This commit is contained in:
parent
a09e101931
commit
f5a4f4321a
|
@ -335,18 +335,24 @@ func ExtractPublicKeyForOwner(i WithPublicKey, forOwner *url.URL) (*rsa.PublicKe
|
||||||
return nil, nil, errors.New("couldn't find public key")
|
return nil, nil, errors.New("couldn't find public key")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractContent returns a string representation of the interface's Content property.
|
// ExtractContent returns a string representation of the interface's Content property,
|
||||||
func ExtractContent(i WithContent) (string, error) {
|
// or an empty string if no Content is found.
|
||||||
|
func ExtractContent(i WithContent) string {
|
||||||
contentProperty := i.GetActivityStreamsContent()
|
contentProperty := i.GetActivityStreamsContent()
|
||||||
if contentProperty == nil {
|
if contentProperty == nil {
|
||||||
return "", nil
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for iter := contentProperty.Begin(); iter != contentProperty.End(); iter = iter.Next() {
|
for iter := contentProperty.Begin(); iter != contentProperty.End(); iter = iter.Next() {
|
||||||
if iter.IsXMLSchemaString() && iter.GetXMLSchemaString() != "" {
|
if iter.IsXMLSchemaString() {
|
||||||
return iter.GetXMLSchemaString(), nil
|
return iter.GetXMLSchemaString()
|
||||||
|
}
|
||||||
|
if iter.IsIRI() && iter.GetIRI() != nil {
|
||||||
|
return iter.GetIRI().String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", errors.New("no content found")
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractAttachments returns a slice of attachments on the interface.
|
// ExtractAttachments returns a slice of attachments on the interface.
|
||||||
|
|
|
@ -92,6 +92,10 @@ func noteWithMentions1() vocab.ActivityStreamsNote {
|
||||||
|
|
||||||
note.SetActivityStreamsTag(tags)
|
note.SetActivityStreamsTag(tags)
|
||||||
|
|
||||||
|
content := streams.NewActivityStreamsContentProperty()
|
||||||
|
content.AppendXMLSchemaString("hey @f0x and @dumpsterqueer")
|
||||||
|
note.SetActivityStreamsContent(content)
|
||||||
|
|
||||||
return note
|
return note
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
42
internal/ap/extractcontent_test.go
Normal file
42
internal/ap/extractcontent_test.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ap_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExtractContentTestSuite struct {
|
||||||
|
ExtractTestSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ExtractContentTestSuite) TestExtractContent1() {
|
||||||
|
note := suite.noteWithMentions1
|
||||||
|
|
||||||
|
content := ap.ExtractContent(note)
|
||||||
|
|
||||||
|
suite.Equal("hey @f0x and @dumpsterqueer", content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractContentTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, &ExtractContentTestSuite{})
|
||||||
|
}
|
|
@ -192,11 +192,7 @@ func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
|
||||||
}
|
}
|
||||||
|
|
||||||
// the html-formatted content of this status
|
// the html-formatted content of this status
|
||||||
if content, err := ap.ExtractContent(statusable); err != nil {
|
status.Content = ap.ExtractContent(statusable)
|
||||||
l.Infof("ASStatusToStatus: error extracting status content: %s", err)
|
|
||||||
} else {
|
|
||||||
status.Content = content
|
|
||||||
}
|
|
||||||
|
|
||||||
// attachments to dereference and fetch later on (we don't do that here)
|
// attachments to dereference and fetch later on (we don't do that here)
|
||||||
if attachments, err := ap.ExtractAttachments(statusable); err != nil {
|
if attachments, err := ap.ExtractAttachments(statusable); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue