sanitize playlist descriptions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
abs3nt 2023-04-15 23:21:48 -07:00
parent 693b228194
commit 81d5135d1a
Signed by: abs3nt
GPG Key ID: FDC6662313FA9386

View File

@ -2,6 +2,7 @@ package tui
import ( import (
"fmt" "fmt"
"regexp"
"sync" "sync"
"time" "time"
@ -12,6 +13,8 @@ import (
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )
const regex = `<.*?>`
func DeviceView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) { func DeviceView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
devices, err := commands.Client().PlayerDevices(ctx) devices, err := commands.Client().PlayerDevices(ctx)
@ -122,7 +125,7 @@ func SearchPlaylistsView(ctx *gctx.Context, commands *commands.Commands, playlis
for _, playlist := range playlists.Playlists { for _, playlist := range playlists.Playlists {
items = append(items, mainItem{ items = append(items, mainItem{
Name: playlist.Name, Name: playlist.Name,
Desc: playlist.Description, Desc: stripHtmlRegex(playlist.Description),
SpotifyItem: playlist, SpotifyItem: playlist,
}) })
} }
@ -291,10 +294,15 @@ func MainView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, erro
for _, playlist := range playlists.Playlists { for _, playlist := range playlists.Playlists {
items = append(items, mainItem{ items = append(items, mainItem{
Name: playlist.Name, Name: playlist.Name,
Desc: playlist.Description, Desc: stripHtmlRegex(playlist.Description),
SpotifyItem: playlist, SpotifyItem: playlist,
}) })
} }
} }
return items, nil return items, nil
} }
func stripHtmlRegex(s string) string {
r := regexp.MustCompile(regex)
return r.ReplaceAllString(s, "")
}