app/post_metadata: add a type cast check for OpenGraph images (#19877)
* app/post_metadata: add a type cast check for OpenGraph images * change log level Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1cc50ff90c
Коммит
b1b9774efa
@@ -295,7 +295,13 @@ func (a *App) getImagesForPost(post *model.Post, imageURLs []string, isNewPost b
|
|||||||
imageURLs = append(imageURLs, a.getImagesInMessageAttachments(post)...)
|
imageURLs = append(imageURLs, a.getImagesInMessageAttachments(post)...)
|
||||||
|
|
||||||
case model.PostEmbedOpengraph:
|
case model.PostEmbedOpengraph:
|
||||||
for _, image := range embed.Data.(*opengraph.OpenGraph).Images {
|
openGraph, ok := embed.Data.(*opengraph.OpenGraph)
|
||||||
|
if !ok {
|
||||||
|
mlog.Warn("Could not read the image data: the data could not be casted to OpenGraph",
|
||||||
|
mlog.String("post_id", post.Id), mlog.String("data type", fmt.Sprintf("%t", embed.Data)))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, image := range openGraph.Images {
|
||||||
var imageURL string
|
var imageURL string
|
||||||
if image.SecureURL != "" {
|
if image.SecureURL != "" {
|
||||||
imageURL = image.SecureURL
|
imageURL = image.SecureURL
|
||||||
|
|||||||
@@ -1222,6 +1222,29 @@ func TestGetImagesForPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("with an invalid OpenGraph image data", func(t *testing.T) {
|
||||||
|
th := Setup(t)
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
||||||
|
})
|
||||||
|
|
||||||
|
post := &model.Post{
|
||||||
|
Metadata: &model.PostMetadata{
|
||||||
|
Embeds: []*model.PostEmbed{
|
||||||
|
{
|
||||||
|
Type: model.PostEmbedOpengraph,
|
||||||
|
Data: map[string]interface{}{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
images := th.App.getImagesForPost(post, []string{}, false)
|
||||||
|
assert.Equal(t, images, map[string]*model.PostImage{})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEmojiNamesForString(t *testing.T) {
|
func TestGetEmojiNamesForString(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user