mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 09:43:36 +02:00
Fix domain name validation #2609
This commit is contained in:
parent
a7def0b7ae
commit
c1b5fc8265
2 changed files with 14 additions and 3 deletions
|
@ -31,9 +31,8 @@ class DomainNameValidator < ActiveModel::EachValidator
|
|||
|
||||
# rubocop: disable Metrics/LineLength
|
||||
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž
|
||||
regexp = /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
|
||||
regexp = /\A[a-zA-Z0-9#{unicode_chars.source}][a-zA-Z0-9#{unicode_chars.source}-]{0,61}[a-zA-Z0-9#{unicode_chars.source}]#{general_domains.source}\z/
|
||||
# rubocop: enable Metrics/LineLength
|
||||
|
||||
# rubocop: disable Style/DoubleNegation
|
||||
!!(value =~ regexp)
|
||||
# rubocop: enable Style/DoubleNegation
|
||||
|
|
|
@ -242,7 +242,7 @@ describe Domain do
|
|||
end
|
||||
|
||||
it 'should not be valid when name length is longer than 63 characters' do
|
||||
d = Fabricate.build(:domain,
|
||||
d = Fabricate.build(:domain,
|
||||
name: "xn--4caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ee")
|
||||
d.valid?
|
||||
d.errors.full_messages.should match_array([
|
||||
|
@ -294,6 +294,18 @@ describe Domain do
|
|||
d.errors.full_messages.should == ["Domain name Domain name is invalid"]
|
||||
end
|
||||
|
||||
it 'should not be valid with at character' do
|
||||
d = Fabricate.build(:domain, name: 'dass@sf.ee')
|
||||
d.valid?
|
||||
d.errors.full_messages.should == ["Domain name Domain name is invalid"]
|
||||
end
|
||||
|
||||
it 'should not be valid with invalid characters' do
|
||||
d = Fabricate.build(:domain, name: '@ba)s(?ä_:-df.ee')
|
||||
d.valid?
|
||||
d.errors.full_messages.should == ["Domain name Domain name is invalid"]
|
||||
end
|
||||
|
||||
it 'should be valid when name length is two pynicodes' do
|
||||
d = Fabricate.build(:domain, name: "xn--4caa.ee")
|
||||
d.valid?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue