This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since upgrading to ruby 2.6.x there have been some tests failures. This commit fixes this situation by upgrading some gems. Moreover, since 1e5d2ac, the UrlValidator class was not being called by the webhook model. I had to re-arrange things a bit to make this part of the code work again. Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
- Loading branch information
Showing
7 changed files
with
86 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require "uri" | ||
|
||
# Validates URLs and transforms them into valid ones if needed. | ||
class HttpValidator < ActiveModel::EachValidator | ||
# Validator for the url. | ||
def validate_each(record, attribute, value) | ||
uri = URI.parse(value) | ||
return if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) | ||
return if generic_enforce_valid(record, uri, value) | ||
|
||
record.errors[attribute] << "is not a valid URL" | ||
rescue URI::InvalidURIError | ||
record.errors[attribute] << "is not a valid URL" | ||
end | ||
|
||
# It returns true if the given uri is URI::Generic and the value does not | ||
# start like "ftp://". In this case, it will modify the record so the url is | ||
# set to its proper value. | ||
def generic_enforce_valid(record, uri, value) | ||
return false unless uri.is_a?(URI::Generic) | ||
|
||
if value.match(%r{^\w+://.+}).nil? | ||
record.url = "http://" + value | ||
true | ||
else | ||
false | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters