From c16965319a90d63fb3e674299c6cd535740b89cd Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 24 Mar 2020 12:17:41 +0100 Subject: [PATCH] Amended processed image URL building to use checks for empty as well as null, and refactored null checks to use HasValue. --- .../Media/ImageProcessorImageUrlGenerator.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Infrastructure/Media/ImageProcessorImageUrlGenerator.cs b/src/Umbraco.Infrastructure/Media/ImageProcessorImageUrlGenerator.cs index 61a12bedf6..f1a0121653 100644 --- a/src/Umbraco.Infrastructure/Media/ImageProcessorImageUrlGenerator.cs +++ b/src/Umbraco.Infrastructure/Media/ImageProcessorImageUrlGenerator.cs @@ -28,18 +28,18 @@ namespace Umbraco.Infrastructure.Media //Only put quality here, if we don't have a format specified. //Otherwise we need to put quality at the end to avoid it being overridden by the format. - if (options.Quality != null && hasFormat == false) imageProcessorUrl.Append("&quality=").Append(options.Quality); - if (options.HeightRatio != null) imageProcessorUrl.Append("&heightratio=").Append(options.HeightRatio.Value.ToString(CultureInfo.InvariantCulture)); - if (options.WidthRatio != null) imageProcessorUrl.Append("&widthratio=").Append(options.WidthRatio.Value.ToString(CultureInfo.InvariantCulture)); - if (options.Width != null) imageProcessorUrl.Append("&width=").Append(options.Width); - if (options.Height != null) imageProcessorUrl.Append("&height=").Append(options.Height); + if (options.Quality.HasValue && hasFormat == false) imageProcessorUrl.Append("&quality=").Append(options.Quality); + if (options.HeightRatio.HasValue) imageProcessorUrl.Append("&heightratio=").Append(options.HeightRatio.Value.ToString(CultureInfo.InvariantCulture)); + if (options.WidthRatio.HasValue) imageProcessorUrl.Append("&widthratio=").Append(options.WidthRatio.Value.ToString(CultureInfo.InvariantCulture)); + if (options.Width.HasValue) imageProcessorUrl.Append("&width=").Append(options.Width); + if (options.Height.HasValue) imageProcessorUrl.Append("&height=").Append(options.Height); if (options.UpScale == false) imageProcessorUrl.Append("&upscale=false"); - if (options.AnimationProcessMode != null) imageProcessorUrl.Append("&animationprocessmode=").Append(options.AnimationProcessMode); - if (options.FurtherOptions != null) imageProcessorUrl.Append(options.FurtherOptions); + if (!string.IsNullOrWhiteSpace(options.AnimationProcessMode)) imageProcessorUrl.Append("&animationprocessmode=").Append(options.AnimationProcessMode); + if (!string.IsNullOrWhiteSpace(options.FurtherOptions)) imageProcessorUrl.Append(options.FurtherOptions); //If furtherOptions contains a format, we need to put the quality after the format. - if (options.Quality != null && hasFormat) imageProcessorUrl.Append("&quality=").Append(options.Quality); - if (options.CacheBusterValue != null) imageProcessorUrl.Append("&rnd=").Append(options.CacheBusterValue); + if (options.Quality.HasValue && hasFormat) imageProcessorUrl.Append("&quality=").Append(options.Quality); + if (!string.IsNullOrWhiteSpace(options.CacheBusterValue)) imageProcessorUrl.Append("&rnd=").Append(options.CacheBusterValue); return imageProcessorUrl.ToString(); }