From 7f3291e75c2f303546f8fd2abb3550b20085419e Mon Sep 17 00:00:00 2001 From: Hugo Hedlund Date: Sun, 14 Jun 2020 00:30:00 +0200 Subject: [PATCH] Check if the url parameter to UrlShortener and UrlUpdate functions is empty and returns an error message if so. --- src/shortenerTools/UrlShortener/UrlShortener.cs | 8 +++++++- src/shortenerTools/UrlUpdate/UrlUpdate.cs | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/shortenerTools/UrlShortener/UrlShortener.cs b/src/shortenerTools/UrlShortener/UrlShortener.cs index 19a55b7b..f3a58242 100644 --- a/src/shortenerTools/UrlShortener/UrlShortener.cs +++ b/src/shortenerTools/UrlShortener/UrlShortener.cs @@ -53,7 +53,13 @@ public static async Task Run( { return req.CreateResponse(HttpStatusCode.NotFound); } - + + // If the Url parameter only contains whitespaces or is empty return with BadRequest. + if (string.IsNullOrWhiteSpace(input.Url)) + { + return req.CreateErrorResponse(HttpStatusCode.BadRequest, "The url parameter can not be empty."); + } + var result = new ShortResponse(); var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) diff --git a/src/shortenerTools/UrlUpdate/UrlUpdate.cs b/src/shortenerTools/UrlUpdate/UrlUpdate.cs index c6d89ecd..6b3bcce9 100644 --- a/src/shortenerTools/UrlUpdate/UrlUpdate.cs +++ b/src/shortenerTools/UrlUpdate/UrlUpdate.cs @@ -62,6 +62,12 @@ public static async Task Run( return req.CreateResponse(HttpStatusCode.NotFound); } + // If the Url parameter only contains whitespaces or is empty return with BadRequest. + if (string.IsNullOrWhiteSpace(input.Url)) + { + return req.CreateErrorResponse(HttpStatusCode.BadRequest, "The url parameter can not be empty."); + } + ShortUrlEntity result; var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory)