Skip to content

Commit

Permalink
Sanitize user input
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Jul 20, 2024
1 parent 0c95cc9 commit b5b82cb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions downloader/Downloader/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public async ValueTask<bool> AddMusicAsync(string songName, string? source, stri
{
try
{
// We sanitize user inputs just in case
songName = songName.Trim();
artist = artist?.Trim();
songType = artist?.Trim();
album = album?.Trim();
albumUrl = albumUrl?.Trim();
source = source?.Trim();

// Create output path
var outMusicPath = GetSongName(songName, artist);
if (!string.IsNullOrWhiteSpace(songType))
Expand Down Expand Up @@ -253,10 +261,10 @@ public string CleanPath(string name)
}

public string GetAlbumName(string? artist, string album)
=> $"{CleanPath(artist ?? "unknown")}_{CleanPath(album)}";
=> $"{CleanPath(artist?.Trim() ?? "unknown")}_{CleanPath(album.Trim())}";

public string GetSongName(string song, string? artist)
=> $"{CleanPath(song)}_{CleanPath(artist ?? "unknown")}";
=> $"{CleanPath(song.Trim())}_{CleanPath(artist?.Trim() ?? "unknown")}";

private JsonExportData _data;
public JsonExportData Data
Expand Down

0 comments on commit b5b82cb

Please sign in to comment.