Add rescue InvalidURIError in mastodon_url validation (#6174) [deploy]
This commit is contained in:
parent
89dd843a50
commit
0b03240e5b
2 changed files with 8 additions and 1 deletions
|
|
@ -81,7 +81,7 @@ class User < ApplicationRecord
|
|||
validates :experience_level, numericality: { less_than_or_equal_to: 10 }, allow_blank: true
|
||||
validates :text_color_hex, format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true
|
||||
validates :bg_color_hex, format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, allow_blank: true
|
||||
validates :website_url, :employer_url, :mastodon_url,
|
||||
validates :website_url, :employer_url,
|
||||
url: { allow_blank: true, no_local: true, schemes: %w[https http] }
|
||||
validates :facebook_url,
|
||||
format: /\A(http(s)?:\/\/)?(www.facebook.com|facebook.com)\/.*\Z/,
|
||||
|
|
@ -612,6 +612,8 @@ class User < ApplicationRecord
|
|||
return if uri.host&.in?(Constants::ALLOWED_MASTODON_INSTANCES)
|
||||
|
||||
errors.add(:mastodon_url, "is not an allowed Mastodon instance")
|
||||
rescue URI::InvalidURIError
|
||||
errors.add(:mastodon_url, "is not a valid url")
|
||||
end
|
||||
|
||||
def tag_list
|
||||
|
|
|
|||
|
|
@ -187,6 +187,11 @@ RSpec.describe User, type: :model do
|
|||
user.mastodon_url = "mastodon.social/@test"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "does not accept an invalid url" do
|
||||
user.mastodon_url = "ben .com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#facebook_url" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue