From fe4967c5826e3277fd5feca36fcfeaef45589be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl-Ian?= Date: Mon, 16 Dec 2024 22:43:57 +0100 Subject: [PATCH] Use URI methods to validate URLs instead of patterns (#70) * Use URI methods to validate URLs instead of patterns --- lib/Dhalang/url_utils.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Dhalang/url_utils.rb b/lib/Dhalang/url_utils.rb index f6894bf..44bbcdc 100644 --- a/lib/Dhalang/url_utils.rb +++ b/lib/Dhalang/url_utils.rb @@ -6,9 +6,10 @@ class UrlUtils # # @param [String] url The url to validate def self.validate(url) - if (url !~ URI::DEFAULT_PARSER.regexp[:ABS_URI]) - raise URI::InvalidURIError, 'The given url was invalid, use format http://www.example.com' - end + parsed = URI.parse(url) # Raise URI::InvalidURIError on invalid URLs + return true if parsed.absolute? + + raise URI::InvalidURIError, 'The given url was invalid, use format http://www.example.com' end end -end \ No newline at end of file +end