Skip to content

Commit c06797f

Browse files
authored
Update regex to allow longer and multi-part TLDs (#453)
## Status - Closes _add issue numbers or delete_ - Related to _add issue numbers or delete_ ## Points for consideration: - Security - Performance ## What's changed? _Description of what's been done - bullets are often best_ ## Steps to perform after deploying to production _If the production environment requires any extra work after this PR has been deployed detail it here. This could be running a Rake task, a migration, or upgrading a Gem. That kind of thing._
1 parent 1eabf8f commit c06797f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

app/models/school.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class School < ApplicationRecord
66
has_many :projects, dependent: :nullify
77
has_many :roles, dependent: :nullify
88

9-
VALID_URL_REGEX = %r{\A(?:https?://)?(?:www.)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,6}(/.*)?\z}ix
9+
VALID_URL_REGEX = %r{\A(?:https?://)?(?:www.)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,63}(\.[a-z]{2,63})*(/.*)?\z}ix
1010

1111
validates :name, presence: true
1212
validates :website, presence: true, format: { with: VALID_URL_REGEX, message: I18n.t('validations.school.website') }

spec/models/school_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
expect(school).to be_invalid
124124
end
125125

126+
it 'accepts a url with a multi-part TLD' do
127+
school.website = 'https://example.co.uk'
128+
expect(school).to be_valid
129+
end
130+
126131
it 'does not require a reference' do
127132
create(:school, id: SecureRandom.uuid, reference: nil)
128133

0 commit comments

Comments
 (0)