Skip to content

Commit

Permalink
clean file extensions for downloaded attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaslovsky committed Jan 21, 2023
1 parent c5775f9 commit 1773b8e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/twitter/tweet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"

tw "github.com/g8rswimmer/go-twitter/v2"
)
Expand Down Expand Up @@ -82,7 +83,9 @@ type Attachment struct {

// Name constructs the file name to use for saving an Attachment
func (a Attachment) Name(tweetID string) string {
return fmt.Sprintf("tweet=%s-media_key=%s%s", tweetID, a.MediaKey, filepath.Ext(a.URL))
// Clean the file extension by removing any invalid params
ext := strings.SplitN(filepath.Ext(a.URL), "?", 2)[0]
return fmt.Sprintf("tweet=%s-media_key=%s%s", tweetID, a.MediaKey, ext)
}

// Download saves an Attachment as a file
Expand Down

0 comments on commit 1773b8e

Please sign in to comment.