Sanitize comments and lyrics on import, as they are rendered as HTML on the UI

This commit is contained in:
Deluan 2020-11-11 12:26:47 -05:00
parent 5111cf8c33
commit 0e7163eb2c
1 changed files with 5 additions and 3 deletions

View File

@ -12,14 +12,16 @@ import (
"github.com/deluan/navidrome/scanner/metadata" "github.com/deluan/navidrome/scanner/metadata"
"github.com/deluan/navidrome/utils" "github.com/deluan/navidrome/utils"
"github.com/kennygrant/sanitize" "github.com/kennygrant/sanitize"
"github.com/microcosm-cc/bluemonday"
) )
type mediaFileMapper struct { type mediaFileMapper struct {
rootFolder string rootFolder string
policy *bluemonday.Policy
} }
func newMediaFileMapper(rootFolder string) *mediaFileMapper { func newMediaFileMapper(rootFolder string) *mediaFileMapper {
return &mediaFileMapper{rootFolder: rootFolder} return &mediaFileMapper{rootFolder: rootFolder, policy: bluemonday.UGCPolicy()}
} }
func (s *mediaFileMapper) toMediaFile(md metadata.Metadata) model.MediaFile { func (s *mediaFileMapper) toMediaFile(md metadata.Metadata) model.MediaFile {
@ -59,8 +61,8 @@ func (s *mediaFileMapper) toMediaFile(md metadata.Metadata) model.MediaFile {
mf.MbzAlbumArtistID = md.MbzAlbumArtistID() mf.MbzAlbumArtistID = md.MbzAlbumArtistID()
mf.MbzAlbumType = md.MbzAlbumType() mf.MbzAlbumType = md.MbzAlbumType()
mf.MbzAlbumComment = md.MbzAlbumComment() mf.MbzAlbumComment = md.MbzAlbumComment()
mf.Comment = md.Comment() mf.Comment = s.policy.Sanitize(md.Comment())
mf.Lyrics = md.Lyrics() mf.Lyrics = s.policy.Sanitize(md.Lyrics())
// TODO Get Creation time. https://github.com/djherbis/times ? // TODO Get Creation time. https://github.com/djherbis/times ?
mf.CreatedAt = md.ModificationTime() mf.CreatedAt = md.ModificationTime()