From 0b3b3dd0bede19b9b5a13e088ceba59a0347aff9 Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Wed, 21 Feb 2018 19:48:00 +0100 Subject: [PATCH] Fix a crash when downloading tweet images with no username Happens when someone accidentally or through dev tools gets to twitter.com and tries downloading an image. --- Core/Utils/TwitterUtils.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Utils/TwitterUtils.cs b/Core/Utils/TwitterUtils.cs index 3eaadc4c..0b292176 100644 --- a/Core/Utils/TwitterUtils.cs +++ b/Core/Utils/TwitterUtils.cs @@ -41,8 +41,8 @@ public static bool IsTwitterWebsite(IFrame frame){ } private static string ExtractMediaBaseLink(string url){ - int dot = url.LastIndexOf('/'); - return dot == -1 ? url : StringUtils.ExtractBefore(url, ':', dot); + int slash = url.LastIndexOf('/'); + return slash == -1 ? url : StringUtils.ExtractBefore(url, ':', slash); } public static string GetMediaLink(string url, ImageQuality quality){ @@ -91,7 +91,7 @@ public static void DownloadImages(string[] urls, string username, ImageQuality q AutoUpgradeEnabled = true, OverwritePrompt = urls.Length == 1, Title = "Save Image", - FileName = $"{string.Join(" ", fileNameParts.Where(part => part.Length > 0))}{ext}", + FileName = $"{string.Join(" ", fileNameParts.Where(part => !string.IsNullOrEmpty(part)))}{ext}", Filter = (urls.Length == 1 ? "Image" : "Images")+(string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}") }){ if (dialog.ShowDialog() == DialogResult.OK){