Skip to content

Commit 1ad801e

Browse files
committed
Fix validating the URL of user home sites
Home site validation used the URL regexp, but didn't anchor it. Because of this it was possible to add text before or after the URL and have it considered valid. For instance, this was considered a valid homesite value: "lorem ipsum https://example.org/#foo#bar dolor sit amet" It is possible to fix it by anchoring the regexp, but IMO it is wiser to use the same URL validator used at other places in the site. Hence this commit replaces this validation with the `http_url` validator used for news links and bookmarks. https://linuxfr.org/suivi/impossible-de-mettre-un-lien-vers-un-salon-matrix-dans-les-liens-d-une-depeche#comment-1911550
1 parent 3ac001b commit 1ad801e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/models/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class User < ActiveRecord::Base
2929
has_many :taggings, -> { includes(:tag) }, dependent: :destroy
3030
has_many :tags, -> { distinct }, through: :taggings
3131

32-
validates_format_of :homesite, message: "L’adresse du site Web personnel n’est pas valide", with: URI::regexp(%w(http https)), allow_blank: true
33-
validates :homesite, length: { maximum: 100, message: "L’adresse du site Web personnel est trop longue" }
32+
validates :homesite, http_url: { protocols: ["https"], message: "L’adresse du site Web personnel n’est pas une URL valide" },
33+
length: { maximum: 100, message: "L’adresse du site Web personnel est trop longue" }
3434
validates :name, length: { maximum: 40, message: "Le nom affiché est trop long" }
3535
validates :jabber_id, length: { maximum: 32, message: "L’adresse XMPP est trop longue" }
3636
validates :signature, length: { maximum: 255, message: "La signature est trop longue" }

0 commit comments

Comments
 (0)