Skip to content

Commit

Permalink
Use URI methods to validate URLs instead of patterns (#70)
Browse files Browse the repository at this point in the history
* Use URI methods to validate URLs instead of patterns
  • Loading branch information
gael-ian authored Dec 16, 2024
1 parent 2fd2e07 commit fe4967c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Dhalang/url_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end

0 comments on commit fe4967c

Please sign in to comment.